Get()
Hello all I am a python "n00b", however I can't find a solution to this problem anywhere. I am using a simple setup - entry box, button and list box, the contents of the entry being inserted into the list box: from Tkinter import * def insert(): name = ent.get() box.insert(0, name) ent.delete(0, END) root = Tk() ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove').grid(row = 0, padx = 3, pady = 3) button = Button(root, text = "Remember", command = insert, relief = 'groove', fg = '#3a3a3a').grid(row = 0, column = 1, padx = 3, pady = 3) box = Listbox(root, bg = '#ebe9ed', relief = 'groove').grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) root.mainloop() When I type something and press the button, i get this error: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "C:\My Documents\My Python\Notes.py", line 6, in insert name = ent.get() AttributeError: 'NoneType' object has no attribute 'get' I am puzzled as to the last line... Help? Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Label Variables
Hi again. I am trying to get the text of the selection in a list box and put into a variable, which is put into a label. i.e., whatever is selected will show in the label. However, because at the beginning there is nothing in the listbox (and therefore no selection), the tuple returned by curselection() is (), therefore when i try and get() from the linenumber in this tuple, the index is "out of range" here is the section of the program: box = Listbox(root, bg = '#ebe9ed', relief = 'groove', height = 15) box.grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) box.bind("", DeleteCurrent) v = StringVar() number = box.curselection() v.set = (box.get(int(number[0]))) print number current = Label(root, textvariable = v) current.grid(row = 3, columnspan = 2, sticky = W+E, padx = 3) and here is the error: Traceback (most recent call last): File "C:\My Documents\My Python\Notes.py", line 27, in v.set = (box.get(int(number[0]))) IndexError: tuple index out of range How can i get it to only take the variable when i have selected something, or any other solution! Thanks, Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Text into a label
Hi again. I am trying to get the text of the selection in a list box and put into a variable, which is put into a label. i.e., whatever is selected will show in the label. However, because at the beginning there is nothing in the listbox (and therefore no selection), the tuple returned by curselection() is (), therefore when i try and get() from the linenumber in this tuple, the index is "out of range" here is the section of the program: box = Listbox(root, bg = '#ebe9ed', relief = 'groove', height = 15) box.grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) box.bind("", DeleteCurrent) v = StringVar() number = box.curselection() v.set = (box.get(int(number[0]))) print number current = Label(root, textvariable = v) current.grid(row = 3, columnspan = 2, sticky = W+E, padx = 3) and here is the error: Traceback (most recent call last): File "C:\My Documents\My Python\Notes.py", line 27, in v.set = (box.get(int(number[0]))) IndexError: tuple index out of range How can i get it to only take the variable when i have selected something, or any other solution! Thanks, Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Im back...
Hi there same project I am afraid... I want to put the text from the selection of a listbox into a Label when the the selection is clicked. I have it so it is put in, but it is put in when I click on the *next*selection...as in it defines the variable when I click on the desired the selection, but it puts it into the label when i click on the *next* item. It is best if you have a look. Here is the whole program [start python code; possibly wrapped by browser] #!/user/bin/python from Tkinter import * def insert(): name = ent.get() box.insert(0, name) ent.delete(0, END) def DeleteCurrent(event): box.delete(ANCHOR) def putLabel(event): selection = box.get(ANCHOR) v.set(str(selection)) root = Tk() ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove') ent.grid(row = 0, padx = 3, pady = 3) button = Button(root, text = "Remember", command = insert, relief = 'groove', fg = '#3a3a3a') button.grid(row = 0, column = 1, padx = 3, pady = 3) box = Listbox(root, bg = '#ebe9ed', relief = 'groove', height = 15) box.selectmode = BROWSE box.grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) box.bind("", DeleteCurrent) box.bind("", putLabel) v = StringVar() current = Label(root, textvariable = v) current.grid(row = 3, columnspan = 2, sticky = W+E, padx = 3) root.mainloop() [end python code] how do i make it so it puts it into the variable *when* i click it? Any help will be greatly appreciated! Thanks, Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Taskbar/System Tray
hello group, Using tkinter, is there any way to have the program not showing on the taskbar, and even better showin in the system tray? I realise tkinter does not have that much OS specific stuff but maybe there is a way? Thanks, Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Newbie question: Classes
Hello all Basically, I have created a program using tkinter without using any class structure, simply creating widgets and functions (and finding ways around passing variables from function to function, using global variables etc). The program has become rather large ( lines?) I am trying to now put it into a class structure, because I hear it is easier to handle. So basically, I put all the stuff into a class, making the widgets in the "def __init__(self, root)" (root being my Tk() ) and then I have had to put a "self." in front of any instance of any variable or widget. Is this right? it seems like nothing is any easier (except having variables locally). Is this right? Should I be creating more classes for different things or what? I can upload the .py if you want. Thanks, Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question: Classes
OK i've kind of got that. The only thing left is calling the class. " class Remember: def __init__(self, master): self.ent = Entry(self, ... root = Tk() app = Remember(root) " I get the error "Remember instance has no attribute 'tk' "...??? On Jan 8, 2008 7:36 PM, Sam Garson <[EMAIL PROTECTED] > wrote: > Hello all > > Basically, I have created a program using tkinter without using any class > structure, simply creating widgets and functions (and finding ways around > passing variables from function to function, using global variables etc). > The program has become rather large ( lines?) I am trying to now put it into > a class structure, because I hear it is easier to handle. > > So basically, I put all the stuff into a class, making the widgets in the > "def __init__(self, root)" (root being my Tk() ) and then I have had to put > a "self." in front of any instance of any variable or widget. Is this right? > it seems like nothing is any easier (except having variables locally). Is > this right? Should I be creating more classes for different things or what? > > I can upload the .py if you want. > > Thanks, > > Sam > > -- > I intend to live forever - so far, so good. > > SaM -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Confusion
I'm just a beginner, but I think I understand some of this: The mainloop is not there to build the window, it is there to check for events, i.e. continually refresh all the widgets. Without, any events you bind will not be detected. Tk() is the first window you make, any after that are toplevel()s. Frame is a widget that I'm sure has benefits in some situations, but I havent found any difference between that and just inheriting from root. Hope this helps. On Feb 17, 2008 7:36 PM, <[EMAIL PROTECTED]> wrote: > Everything I've read about Tkinter says you create your window and > then call its mainloop() method. But that's not really true. This is > enough to launch a default window from the console: > > >>>from Tkinter import * > >>>foo = Tk() > > Google's great, but it has no truth meter. Do I inherit from Frame? Or > is that a big mistake. (Both positions repeated frequently.) Do I use > Tk() or toplevel()? (Support for both and if a cogent explanation of > the differences exists, I didn't find it.) > > Here's the application. I'm creating a visual parser for my beginner's > language. The starting position is a list of Statement objects, each > being a list of Token objects. The statement is presented as a list of > buttons with abbreviated token types ('Con_Int' for a CONSTANT_INTEGER > token). Click the button and a dialog-like info display pops up with > all the details about the token. During parsing, each recognition > condenses tokens into productions, shortening the Statement. (Example: > three Token buttons are replaced by one Addition production button.) > An application window provides for stepping through the parsing and > provides utility commands such as "Close all those token windows I've > got lying all over". > > Much less complex than IDLE, but GvR and cohorts seem to understand > what's really going on. I don't. Help appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list > -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Re: Why """, not '''?
The """ is for the docstring - if you need the user to know what theyre doing with the program you can create documentation, and what you put in those quotes wwill come up in that (I think) On 3/6/08, Dotan Cohen <[EMAIL PROTECTED]> wrote: > > On 06/03/2008, Dan Bishop <[EMAIL PROTECTED]> wrote: > > On Mar 5, 7:24 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > > > > > Steven D'Aprano wrote: > > > > Surely it would depend on the type of text: pick up any random > English > > > > novel containing dialogue, and you're likely to find a couple of > dozen > > > > pairs of quotation marks per page, against a few apostrophes. > > > > > > > > That's an idea... Write a novel in Python docstrings. > > > > > > Or better yet, write in Python syntax. > > > > > > assert len([man for man in now_alive() if > > man.remembers(datetime.date(1775, 4, 18))]) <= HARDLY > > > > lantern_count = {'land': 1, 'sea': 2}.get(british.location(), 0) > > n_ch_twr.hang(Lantern() for _ in xrange(lantern_count)) > > > > if lantern_count: > > for village in middlesex: > > ride_thru(village) > > spread_alarm(village) > > > > That looks ported from lolcode. > http://lolcode.com/ > > Dotan Cohen > > http://what-is-what.com > http://gibberish.co.il > א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת > > A: Because it messes up the order in which people normally read text. > Q: Why is top-posting such a bad thing? > -- > http://mail.python.org/mailman/listinfo/python-list -- I like kids, but I don't think I could eat a whole one... -- http://mail.python.org/mailman/listinfo/python-list