I have been trying to learn how to associate keyboard events with actions taken by a Python program using Tkinter. From what I've read online, it seems that this is done with the bind methods. In one of my programs, I have included the following:
self.enternumber = Entry(self)
self.enternumber.bind("<Return>",self.quit)
self.enternumber.pack({"side":"top"})
It seems to me that, as a result of this code, if the enternumber Entry widget is selected and then the <Return> key is pressed, then the program should quit. Indeed, it seems that the program does attempt to quit, but instead an error message appears claiming that quit() takes 1 argument but 2 are given. I get the same type of error if I replace self.quit with some function that I have written. I am not sure how to fix this problem and hope that someone here can spot my error. Thanks for your help.
Shankar 2 5319
Shankar Iyer (si***@Princeton.EDU) wrote: I have been trying to learn how to associate keyboard events with actions taken by a Python program using Tkinter. From what I've read online, it seems that this is done with the bind methods. In one of my programs, I have included the following:
self.enternumber = Entry(self) self.enternumber.bind("<Return>",self.quit) self.enternumber.pack({"side":"top"})
It seems to me that, as a result of this code, if the enternumber Entry widget is selected and then the <Return> key is pressed, then the program should quit. Indeed, it seems that the program does attempt to quit, but instead an error message appears claiming that quit() takes 1 argument but 2 are given. I get the same type of error if I replace self.quit with some function that I have written. I am not sure how to fix this problem and hope that someone here can spot my error. Thanks for your help.
Shankar
Have you defined quit function?
Hi!
If you press a key, a key-event is passed to the function, here to
self.quit. This is the misterious second argument, which can be
useful if you e.g. want to check which key was pressed. Here is
a snippet to show how you can do it:
from Tkinter import *
def quit_program(event):
print event.keysym # which key was pressed?
root.quit()
root = Tk()
e = Entry()
e.bind("<Return>", quit_program)
e.pack()
root.mainloop()
Regards, mawe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: Dowding George A |
last post by:
Brent B. Welch gives this example in _Practical Programming in Tcl and Tk_.
bindtags $t
bind ViInsert <Escape> {bindtags %W {ViCmd %W all}}
bind ViCmd <Key-i> {bindtags %W {ViInsert Text %W...
|
by: Binny V A |
last post by:
Hello Everyone,
I am new to python and I am trying to get a program
to close a application when the Escape Key is pressed.
This is the code that I used
---------------------------------...
|
by: Nicholas Shewmaker |
last post by:
(I apologize if this posts twice. My AVG is being fussy.)
From what I've read, MouseWheel is a very tricky event. I have
replaced my Python tcl84.dll and tk84.dll files with those in the...
|
by: Michael Yanowitz |
last post by:
Hello:
Below I have included a stripped down version of the GUI I am working on.
It contains 2 dialog boxes - one main and one settings. It has the following
problems, probably all related, that...
| |
by: Davy |
last post by:
Hi all,
I have a canvas and a rectangle draw on it. Can I bind a key(e.g. UP)
to the canvas and make the rectangle move up? Or shall I bind the key
to rectangle(I don't think so, because it is...
|
by: dampflames |
last post by:
I put tag binds on the image inside a function, but even though I haven't called it, the tags are initiated when I start the program, and then it won't work again. I'm not quite sure why it is like...
|
by: karthikbalaguru |
last post by:
Hi,
One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to...
|
by: dudeja.rajat |
last post by:
Hi,
I'm using Tkinter and Tix. I've created a combo box which I am able to
fill it up.
I'm want to call a function as soon as user selects some thing from
the combo box.
More precisely, I want...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |