473,624 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUI text entry tkinter

31 New Member
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 10505
boxfish
469 Recognized Expert Contributor
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 New Member
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 Recognized Expert Contributor
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 New Member
@boxfish
ahh thanks boxfish!!
Mar 31 '09 #5
boxfish
469 Recognized Expert Contributor
You're welcome, glad it worked.
Mar 31 '09 #6
v13tn1g
31 New Member
hmm acutally inputting that code didn't work :s, it still says q1_data is not defined
Mar 31 '09 #7
bvdet
2,851 Recognized Expert Moderator Specialist
Try making the global declaration inside function run_analyse(db).

-BV
Mar 31 '09 #8
boxfish
469 Recognized Expert Contributor
@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 Recognized Expert Moderator Specialist
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

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

Similar topics

1
2700
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
17931
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 each of the widgets using a temp variable to hold the text, but I don't wnat to reinvent the wheel if there already is something that does the job. Thanks, Bill
1
1964
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
5068
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 text in the menus entries is to destroy them and recreate them usiing different labels. This seems very clunky though, and there must be a better way. Can anyone offer any pointers or a short example for how to do this? Thanks, Phil
2
1651
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 information about text entry, into CMSs or text-based HTML editors, on Windows systems. Can anyone advise, or suggest reference material, please? -- Andy Mabbett * Say "NO!" to compulsory ID Cards: <http://www.no2id.net/>
6
1433
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 the submit button, absolutely nothing happens. IDLE doesn't give an error message and the note is not entered into the text file. For troubleshooting puposes, I wanted to see if IDLE would at least print the user's input; it doesn't do that...
1
2206
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 to get the materials 2) Any sample of T9 algorithms. 3) If is there any other information, pls share with me. It would be very helpful. Thanks and regards,
3
5769
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 the process of showing whatever the user inputs in the Text Entry to the Text View. Here's part of my code: void on_send_button_clicked (GtkButton *button, gpointer user_data) { const char* input;
2
16075
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 in the entry field? I don't want whatever is typed in to print out to IDLE. So as an example: from Tkinter import * win = Tk() Label(win, text='Enter user nick:').pack(side=LEFT) Entry(win, width=20).pack(side=LEFT) mainloop()
0
8234
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8677
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, 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...
0
8620
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 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...
1
8335
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,...
0
8474
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 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...
0
7158
agi2029
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...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
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...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.