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
13 10474
I haven't written a Tkinter program for a while, but it looks like you can clear a text entry like this:
Is that what you're looking for?
for some reason that isnt working for me... - def evClear():
-
q1_data.delete(0,END)
-
q2_data.delete(0,END)
-
q3_data.delete(0,END)
-
q3_data2.delete(0,END)
-
-
-
def quit(window):
-
window.destroy()
-
-
def run_analyse(db):
-
window = Tk()
-
-
-
frame = Frame(window)
-
frame.pack()
-
-
q1_prompt = Label(frame, text="Enter a series:")
-
q1_prompt.grid(row=0, column=0)
-
q1_data= Entry(frame)
-
q1_data.grid(row=0, column=1)
-
-
q2_prompt = Label(frame, text="Enter an element:")
-
q2_prompt.grid(row=2, column=0)
-
q2_data = Entry(frame)
-
q2_data.grid(row=2, column=1)
-
-
q3_prompt = Label(frame, text="Enter the first element:")
-
q3_prompt.grid(row=4, column=0)
-
q3_data = Entry(frame)
-
q3_data.grid(row=4, column=1)
-
q3_prompt2 = Label(frame, text="Enter the second element:")
-
q3_prompt2.grid(row=5, column=0)
-
q3_data2 = Entry(frame)
-
q3_data2.grid(row=5, column=1)
-
-
b1 = Button(frame, text = "Enter")
-
b1.grid(row=6, column=1)
-
-
quit_button = lambda : quit(window)
-
b2 = Button(frame, text = "Quit", command = quit_button)
-
b2.grid(row=8, column=1)
-
-
-
bClear = Button(frame, text="Clear", command = evClear)
-
bClear.grid(row=7, column=1)
-
-
-
window.mainloop()
-
-
-
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
The text entries are global variables, so evClear is not allowed to access them unless you explicitly say so. Use the global keyword: -
def evClear():
-
global q1_data, q2_data, q3_data, q3_data2
-
q1_data.delete(0,END)
-
q2_data.delete(0,END)
-
q3_data.delete(0,END)
-
q3_data2.delete(0,END)
-
I hope this helps.
You're welcome, glad it worked.
hmm acutally inputting that code didn't work :s, it still says q1_data is not defined
bvdet 2,851
Expert Mod 2GB
Try making the global declaration inside function run_analyse(db).
-BV
@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.
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.
@bvdet
how would i do that?..i've never learnt about global before..:s
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. - global q1_data, q2_data, q3_data, q3_data2
hahha thanks bvdet it works perfectly!! btw i had to add it before the names were mentioned.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: WOJSAL |
last post by:
I want show HTML-text (messages, textarea etc.)
with TkInter. What free package, module i need?
Please help.
--
Regards
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |