473,578 Members | 3,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Tkinter problem

Hi all,

I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the previous
widgets when they pop up. How do I reinitialize the widget each time so
that it doesn't contain earlier ones? Actually, another question I have
is, is there a way to set python so that it will assume any undefined
variable is 0 or ''? That is, I have several statements like "If k 0
then so and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the program but
it seems there should be a better way.

Greg

Nov 7 '06 #1
4 1567
On 2006-11-07, gm********@gmai l.com <gm********@gma il.comwrote:
I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the
previous widgets when they pop up. How do I reinitialize the
widget each time so that it doesn't contain earlier ones?
Show your code.
Actually, another question I have is, is there a way to set
python so that it will assume any undefined variable is 0 or
''? That is, I have several statements like "If k 0 then so
and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the
program but it seems there should be a better way.
The best way to do it is to never use undefined names.

--
Neil Cerutti
If only faces could talk. --Pat Summerall
Nov 7 '06 #2
Here's my Tkinter class:

class TwoChoice:
def __init__(self, master):

frame = Frame(master)
frame.pack()
m = Label(root, text= maentry)
m.pack()
n = Label(root, text= fave)
n.pack()

self.button = Button(frame, text=home_team, command=
self.comm_1)
self.button.pac k(side=LEFT)

self.hi_there = Button(frame, text=vis_team,
command=self.co mm_2)
self.hi_there.p ack(side=LEFT)

def comm_1(self):
print home_team
root.quit()

def comm_2(self):
print vis_team
root.quit()

I call it by

root = Tk()
gui= TwoChoice(root)
root.mainloop()

The next time I call it I want to just run the same thing but with
different values for the variables. Instead it gives me like two copies
of the widget.

Greg

Neil Cerutti wrote:
On 2006-11-07, gm********@gmai l.com <gm********@gma il.comwrote:
I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the
previous widgets when they pop up. How do I reinitialize the
widget each time so that it doesn't contain earlier ones?

Show your code.
Actually, another question I have is, is there a way to set
python so that it will assume any undefined variable is 0 or
''? That is, I have several statements like "If k 0 then so
and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the
program but it seems there should be a better way.

The best way to do it is to never use undefined names.

--
Neil Cerutti
If only faces could talk. --Pat Summerall
Nov 7 '06 #3

Greg,

Run the following code to see how pack_forget() or
grid_forget() works, it makes previous widgets
disappear but not go away. If you call grid() or
pack() again after using grid_forget() the widget
returns.
root = Tk()
class Ktest:
def __init__(self):
self.Ftest1()

def Ftest1(self):

try:
self.test2.grid _forget()
except AttributeError :
pass
self.test1 = Button(root, text='Push #1
button', bg = 'yellow', width = 25,
command = self.Ftest2,
height = 25)
self.test1.grid (row=0, column=0)
def Ftest2(self):
self.test1.grid _forget()
self.test2 = Button(root, text='Push #2
button', bg = 'green',
width = 15,
command = self.Ftest1,
height = 10)
self.test2.grid (row=0, column=0)

if __name__== '__main__' :
Ktest()
mainloop()

Maybe someone else has an idea about not defining
a variable.

My question is how does a budket of wires and
screws know its a bucket of wires and screws
unless someone tells it that it's a bucket of
wires and screws?


On Tuesday 07 November 2006 09:35,
gm********@gmai l.com wrote:
Hi all,

I'm trying to write a GUI that will put up
multiple widgets in succession. My problem is
that each widget also contains the previous
widgets when they pop up. How do I reinitialize
the widget each time so that it doesn't contain
earlier ones? Actually, another question I have
is, is there a way to set python so that it
will assume any undefined variable is 0 or ''?
That is, I have several statements like "If k >
0 then so and so" and I would like it to assume
k=0 unless I tell it otherwise. I've just been
defining k=0 at the start of the program but it
seems there should be a better way.

Greg
Nov 7 '06 #4
On Tuesday 07 November 2006 10:38, jim-on-linux
wrote:
Greg,

Run the following code to see how pack_forget()
or grid_forget() works, it makes previous
widgets disappear but not go away. If you call
grid() or pack() again after using
grid_forget() the widget returns.
root = Tk()
class Ktest:
def __init__(self):
self.Ftest1()

def Ftest1(self):

try:
self.test2.grid _forget()
except AttributeError :
pass
self.test1 = Button(root, text='Push #1
button', bg = 'yellow',
width = 25,
command = self.Ftest2, height = 25)
self.test1.grid (row=0, column=0)
def Ftest2(self):
self.test1.grid _forget()
self.test2 = Button(root, text='Push #2
button', bg = 'green',
width = 15,
command = self.Ftest1,
height = 10)
self.test2.grid (row=0, column=0)

if __name__== '__main__' :
Ktest()
mainloop()

Maybe someone else has an idea about not
defining a variable.

My question is how does a budket of wires and
screws know its a bucket of wires and screws
unless someone tells it that it's a bucket of
wires and screws?

jim-on-linux

http://.www.inqvista.com
>


On Tuesday 07 November 2006 09:35,

gm********@gmai l.com wrote:
Hi all,

I'm trying to write a GUI that will put up
multiple widgets in succession. My problem is
that each widget also contains the previous
widgets when they pop up. How do I
reinitialize the widget each time so that it
doesn't contain earlier ones? Actually,
another question I have is, is there a way to
set python so that it will assume any
undefined variable is 0 or ''? That is, I
have several statements like "If k 0 then
so and so" and I would like it to assume k=0
unless I tell it otherwise. I've just been
defining k=0 at the start of the program but
it seems there should be a better way.

Greg
Nov 8 '06 #5

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

Similar topics

3
7014
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter import * class App:
2
3235
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make. My button bar is implemented a Frame subclass, which takes the button dictionary as an argument and displays the buttons on the screen: class...
7
11889
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of wxPython. Mitchell Timin -- "Many are stubborn in pursuit of the path they have chosen, few in
1
3841
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker based on a Text widget with embedded windows and a thread running the Tkinter mainloop plus several other thread dealing with the scheduling of the...
2
4072
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I open a python interpreter and run my subprocess command, all is well. But when I run the same command from inside a Tkinter app, I'm getting errors.
1
3588
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings...
1
1426
by: jkuo22 | last post by:
Hi everyone, Here is my simple Tkinter script: ## start of entry.py from Tkinter import * root=Tk() e1=Entry(root, width=16) e1.pack() e2=Entry(root, width=16)
1
1885
by: mohan | last post by:
Hello Guys, I am a beginner with Python programming and would like to implement some GUI functionalities along with my main work. So I was trying to implement one basic program (available from books). Here is the code, ############################ import Tkinter
0
1534
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
3
3907
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new...
0
7847
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...
0
7778
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
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. ...
1
7874
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...
0
8148
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...
1
5664
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...
0
5342
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3781
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...
1
2292
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.