Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Python Tkinter Help


ghost's Avatar
0 0

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.

        #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
```markupclass Application(Frame):```

Any help? :]

Demons Halo's Avatar
Member
0 0

I've not used classes before but as far as I know your widgets must be included in the "master" window like this:

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.daniweb.com/forums/thread39404.html#


ghost's Avatar
0 0

+1 i believe demon is correct must be within.


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

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().


ghost's Avatar
0 0

Rapt0r wrote: [quote]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().[/quote]

Thanks. That was just what I needed :] Works fine now :)


ghost's Avatar
0 0

x_5631 wrote: Thanks. That was just what I needed :] Works fine now :)

No problem.