473,804 Members | 3,526 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 1576
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
7038
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
3252
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 OptionsBar(Frame): def __init__(self, buttonDict, parent=None) Frame.__init__(self, parent)
7
11909
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
3865
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 contents and the acquisition of data but not using graphic widgets. I run the same code on Linux...
2
4089
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
3604
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 Panel. I just want it to bring up one. Is there an easy way to do that?
1
1442
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
1893
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
1549
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
3921
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 window respectively having
0
9708
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
9588
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
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
10327
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
9161
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...
0
5527
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
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
3
2999
bsmnconsultancy
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...

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.