Hello to everybody!!
I am running Python 2.5.1 on Windows Vista and i have a problem with the
"Entry" widget of Tkinter. Take a look at this code: -
from Tkinter import *
-
-
def fetch():
-
q=(e.get())
-
print q
-
-
root=Tk()
-
f=Frame(root)
-
f.pack()
-
e=Entry(f,width=26)
-
e.pack()
-
e.focus()
-
-
e.bind("<Any-KeyPress>",(lambda event: fetch()))
-
-
root.mainloop()
The problem i have ( as you can verify if you run the script) , is that
although the first Key-Press is shown in the Entry field , the computer
doesn't assign it to the variable which it is assigned , until a SECOND
Key-Press occurs. The same goes for the second one ( although it appears on the
widget , its not assigned until the THIRD Key-Press occurs ) and so on...
Could anyone tell me if this is normal behaviour (and if so how can i "correct" it,
or my code has some kind of flaw?
Many thanks in advance!!!!
3 1912
Hello to everybody!!
I am running Python 2.5.1 on Windows Vista and i have a problem with the
"Entry" widget of Tkinter. Take a look at this code: -
from Tkinter import *
-
-
def fetch():
-
q=(e.get())
-
print q
-
-
root=Tk()
-
f=Frame(root)
-
f.pack()
-
e=Entry(f,width=26)
-
e.pack()
-
e.focus()
-
-
e.bind("<Any-KeyPress>",(lambda event: fetch()))
-
-
root.mainloop()
The problem i have ( as you can verify if you run the script) , is that
although the first Key-Press is shown in the Entry field , the computer
doesn't assign it to the variable which it is assigned , until a SECOND
Key-Press occurs. The same goes for the second one ( although it appears on the
widget , its not assigned until the THIRD Key-Press occurs ) and so on...
Could anyone tell me if this is normal behaviour (and if so how can i "correct" it,
or my code has some kind of flaw?
Many thanks in advance!!!!
The problem is that you are calling e.get() before the entry widget gets the key press. I think you can fix it with this: -
def fetch(event):
-
print event.char + e.get()
-
-
-
e.bind("<Any-KeyPress>", fetch)
-
If that doesn't work, try printing another member of the event object.
bartonc 6,596
Recognized Expert Expert
The problem is that you are calling e.get() before the entry widget gets the key press. I think you can fix it with this: -
def fetch(event):
-
print event.char + e.get()
-
-
-
e.bind("<Any-KeyPress>", fetch)
-
If that doesn't work, try printing another member of the event object.
I like it!
It may be the other way 'round, though: -
def fetch(event):
-
print e.get() + event.char
-
# and maybe like this is more general
-
# print event.widget.get() + event.char
-
-
e.bind("<Any-KeyPress>", fetch)
-
Dear friends ,
I am realy GRATEFULL for your quick and helpfull reply!!!!
I was trying to do solve this problem for 3 days (..and nights...) and realy got
frustrated..... ..
Thanks again!!!!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Schmidt |
last post by:
I'm trying to make a custom entry widget, as in the code that follows.
There are two problems I'm trying to fix:
1) I would like the widget to behave as myEntry.Escape() does now,
except that it happens on loss of focus, not when pressing Esc.
2) TABbing between multiple entry fields does undesired things with
the selection, and with cursor placement.
Can anyone offer any suggestions for how to fix this? I'm attemting to
|
by: Elaine Jackson |
last post by:
I've got a script where a button gets pushed over and over: to cut down on the
carpal tunnel syndrome I'd like to have the button respond to presses of the
Enter key as well as mouse clicks; can somebody clue me in regarding how this is
done? Muchas gracias.
Peace
|
by: Pekka Niiranen |
last post by:
Hi there,
after reading TkInter/thread -recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965
I wondered if it was possible to avoid using threads
for the following problem:
I have script started from W2K console that normally
prints ascii messages to the screen. However, I have
command line "debug" -flag that might cause printing
|
by: William Gill |
last post by:
I am trying to get & set the properties of a widget's parent widget.
What I have works, but seems like a long way around the block. First I
get the widget name using w.winfo_parent(), then i convert the name to a
reference using nametowidget().
self.nametowidget(event.widget.winfo_parent()).hasChanged= True
It works, but I can't help but think I'm missing a more direct route. Am I?
Bill
|
by: Matt Hammond |
last post by:
Here's a strange one in Tkinter that has me stumped:
(I'm running python 2.4 on Suse Linux 9.3 64bit)
I'm trying to make a set of Entry widgets with Label widgets to the left
of each one, using the grid layout. If I make and grid the Label *before*
the Entry then the Entry widget doesn't seem to work - it lets me put the
cursor in it, but I can't type! See example code below.
Is this just me doing something really really silly, or is...
| |
by: swisscheese |
last post by:
I must be missing something basic.
Can anyone explain why 'A' does not show on the entry widget?
import Tkinter
root = Tkinter.Tk()
class Col:
Rows =
def __init__(self):
Frame = Tkinter.Frame(root);
Frame.pack (side='left')
|
by: Lie |
last post by:
Inspect the following code:
--- start of code ---
import Tkinter as Tk
from Tkconstants import *
root = Tk.Tk()
e1 = Tk.Entry(root, text = 'Hello World')
e2 = Tk.Entry(root, text = 'Hello World')
|
by: C Martin |
last post by:
What am I doing wrong in this code? The callback doesn't work from the Entry widget.
##start code
import Tkinter
tk = Tkinter.Tk()
var = Tkinter.StringVar()
print var._name
def cb(name, index, mode):
|
by: Leonhard Vogt |
last post by:
Hello
I have the following problem in Python 2.5 on Windows XP.
On Ubuntu I do not see the problem.
I have a Tkinter application as in the following example
The entry-widget is somehow blocked (i cannot type characters into it)
when I call askopenfilename before I create the widget.
Calling askopenfile again (by clicking the button) releases the block,
I can type into the entry as expected.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |