473,480 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

bind in Tkinter


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
Jul 19 '05 #1
2 5319
VK
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?
Jul 19 '05 #2
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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5951
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...
0
1525
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...
2
7369
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 ---------------------------------...
1
11156
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...
1
3575
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...
1
2595
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...
1
2696
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...
8
3260
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...
0
1014
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...
0
7088
jinu1996
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...
1
6741
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...
0
6956
tracyyun
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...
1
4783
isladogs
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...
0
4485
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...
0
2997
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...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.