473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

GUI text entry tkinter

31
so basically my GUI window has 4 text entries where the user inputs stuff. i have created a clear button with in my window, the thing that i was wondering is how do i create a function to associate with the clear button to clear all text entries entered by the user?.

thanks
Mar 30 '09 #1
13 10474
boxfish
469 Expert 256MB
I haven't written a Tkinter program for a while, but it looks like you can clear a text entry like this:
Expand|Select|Wrap|Line Numbers
  1. myEntry.delete(0, END)
Is that what you're looking for?
Mar 30 '09 #2
v13tn1g
31
for some reason that isnt working for me...

Expand|Select|Wrap|Line Numbers
  1. def evClear():
  2.     q1_data.delete(0,END)
  3.     q2_data.delete(0,END)
  4.     q3_data.delete(0,END)
  5.     q3_data2.delete(0,END)
  6.  
  7.  
  8. def quit(window):
  9.     window.destroy()
  10.  
  11. def run_analyse(db):
  12.     window = Tk()
  13.  
  14.  
  15.     frame = Frame(window)
  16.     frame.pack()
  17.  
  18.     q1_prompt = Label(frame, text="Enter a series:")
  19.     q1_prompt.grid(row=0, column=0)
  20.     q1_data= Entry(frame)
  21.     q1_data.grid(row=0, column=1)
  22.  
  23.     q2_prompt = Label(frame, text="Enter an element:")
  24.     q2_prompt.grid(row=2, column=0)
  25.     q2_data = Entry(frame)
  26.     q2_data.grid(row=2, column=1)
  27.  
  28.     q3_prompt = Label(frame, text="Enter the first element:")
  29.     q3_prompt.grid(row=4, column=0)
  30.     q3_data = Entry(frame)
  31.     q3_data.grid(row=4, column=1)   
  32.     q3_prompt2 = Label(frame, text="Enter the second element:")
  33.     q3_prompt2.grid(row=5, column=0)
  34.     q3_data2 = Entry(frame)
  35.     q3_data2.grid(row=5, column=1)
  36.  
  37.     b1 = Button(frame, text = "Enter")
  38.     b1.grid(row=6, column=1)
  39.  
  40.     quit_button = lambda : quit(window)
  41.     b2 = Button(frame, text = "Quit", command = quit_button)
  42.     b2.grid(row=8, column=1)
  43.  
  44.  
  45.     bClear = Button(frame, text="Clear", command = evClear)
  46.     bClear.grid(row=7, column=1)
  47.  
  48.  
  49.     window.mainloop()
  50.  
  51.  
  52.  
for some reason it doesnt clear the entries....it says that they are not defined...such as q1_data is not defined...but it is :s can you debug this?

thanks
Mar 31 '09 #3
boxfish
469 Expert 256MB
The text entries are global variables, so evClear is not allowed to access them unless you explicitly say so. Use the global keyword:
Expand|Select|Wrap|Line Numbers
  1. def evClear():
  2.     global q1_data, q2_data, q3_data, q3_data2
  3.     q1_data.delete(0,END)
  4.     q2_data.delete(0,END)
  5.     q3_data.delete(0,END)
  6.     q3_data2.delete(0,END)
  7.  
I hope this helps.
Mar 31 '09 #4
v13tn1g
31
@boxfish
ahh thanks boxfish!!
Mar 31 '09 #5
boxfish
469 Expert 256MB
You're welcome, glad it worked.
Mar 31 '09 #6
v13tn1g
31
hmm acutally inputting that code didn't work :s, it still says q1_data is not defined
Mar 31 '09 #7
bvdet
2,851 Expert Mod 2GB
Try making the global declaration inside function run_analyse(db).

-BV
Mar 31 '09 #8
boxfish
469 Expert 256MB
@bvdet
Wow, that works! That really baffles me. What is the global statement doing? Is it actually turning them into global variables? I thought the global statement only made variables available for the function that used it. I definitely learned something today.
Mar 31 '09 #9
bvdet
2,851 Expert Mod 2GB
When Python resolves an identifier, it first checks the local namespace, then checks the global namespace, and then checks the __builtins__ namespace before raising a NameError exception. The global namespace for a function is always the module in which the function is defined.
Mar 31 '09 #10
v13tn1g
31
@bvdet
how would i do that?..i've never learnt about global before..:s
Mar 31 '09 #11
bvdet
2,851 Expert Mod 2GB
Add the following statement inside the body of function run_analyse(db) after the names have been assigned an object.
Expand|Select|Wrap|Line Numbers
  1. global q1_data, q2_data, q3_data, q3_data2
Mar 31 '09 #12
v13tn1g
31
hahha thanks bvdet it works perfectly!! btw i had to add it before the names were mentioned.
Mar 31 '09 #13
bvdet
2,851 Expert Mod 2GB
v13tn1g,

I am pleased it works for you. Yes, the global declaration must be made before the assignment. I have not used global in years, and I forgot the proper syntax.
Mar 31 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WOJSAL | last post by:
I want show HTML-text (messages, textarea etc.) with TkInter. What free package, module i need? Please help. -- Regards
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
1
by: utabintarbo | last post by:
Is there a native Win32 text entry dialog available through the Win32 extensions. I am looking for something similar to easygui's (http://www.ferg.org/easygui/) enterbox. Any ideas? TIA
5
by: Phil Schmidt | last post by:
I am making a little Tkinter GUI app that needs to be in several languages (english, french, etc.), adjustable at runtime via a menu pick to select the language. The only way I can see to change...
2
by: Andy Mabbett | last post by:
Although I only speak English, I need to learn techniques for publishing text using non-European scripts (initially Urdu & Punjabi). I think I'm getting there, but I'm having problems finding...
6
by: Chad | last post by:
I have a simple little program that brings up asks the user to enter a note, then is supposed to place that note into a text file when the user hits the submit button. However, when the user hits...
1
by: oravm | last post by:
I am developing a tool for predictive text entry for sms on a mobile phone. The language used is J2ME and RMS database. Please guide me on the following:- 1) The relevant references or websites...
3
by: rhen18 | last post by:
Hi everyone. I am creating a basic chat interface in Glade that contains only 3 widgets namely Text View, Text Entry and Button. Like I said, it is very basic. However I am having a problem with...
2
Thekid
by: Thekid | last post by:
I have a toplevel window in tkinter that has some entry fields. Is there a way that I can get it to change the letters typed in it to uppercase, either as they're typed or after they're typed, while...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...
0
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 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.