Author | Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
I'm trying to bind a key to a command, but it doesn't seem to be working. As far as I know, I need to bind it to the dialogue, which is what I'm doing, and nothing happens.
I don't get any errors, the program runs fine, but when I press the key nothing happens.
Code def createWidgets(self):
#self.rowconfigure(0, weight=1)
#self.columnconfigure(0, weight=1)
self.quitButton = Button(self, text="Exit", command=self.closer)
self.okButton = Button(self, text="Ok", command=self.check)
self.urlField = Entry(self)
self.urlLabel = Label(self, text="URL:")
self.urlField.bind("<Return>", self.check)
self.bind("<F6>", self.worked)
self.urlLabel.grid(row=0, sticky=W, padx=5, pady=10)
self.urlField.grid(row=0, column=1, padx=5)
self.okButton.grid(row=0, column=2, padx=5, pady=20)
self.quitButton.grid(row=1)
Which is part of the class
Code class Application(Frame):
Any help? :]
|
 |
Author | RE: Python Tkinter Help |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
I've not used classes before but as far as I know your widgets must be included in the "master" window like this:
Code
master = Tk()
quitbutton=Button(master, text="Quit", command=master.destroy)
I'm a GUI beginner like you are so I might be wrong about this :P
also, check this link:
http://www.daniwe. . .9404.html#
Edited by Demons Halo on 20-06-09 19:33 |
 |
Author | RE: Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
+1 i believe demon is correct must be within.
|
 |
Author | RE: Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
Sorry, I should have pointed out... the buttons and everything all work.. I just posted such a big chunk of code so people could get an idea where the bit that doesn't work is.
It's just the "self.bind(blahblahblah)" that doesn't work.
Even the "self.urlField.bind(blahblahblah)" works.
|
 |
Author | RE: Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
x_5631 wrote:
It's just the "self.bind(blahblahblah)" that doesn't work.
Even the "self.urlField.bind(blahblahblah)" works.
If your trying to bind a key event to a parent widget like a frame, you have to use bind_all() instead of bind(). |
 |
Author | RE: Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
Rapt0r wrote:
x_5631 wrote:
It's just the "self.bind(blahblahblah)" that doesn't work.
Even the "self.urlField.bind(blahblahblah)" works.
If your trying to bind a key event to a parent widget like a frame, you have to use bind_all() instead of bind().
Thanks. That was just what I needed :]
Works fine now 
|
 |
Author | RE: Python Tkinter Help |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
x_5631 wrote:
Thanks. That was just what I needed :]
Works fine now 
No problem. |
 |