472,353 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Having problems using Tkinter

Hi everyone ! ! !

I'm just a month old in the world of Python and trying to develop an
application using Tkinter in which a new window pops out on a
particular button press.The code for this new window is in
"AddKlas.py" file.
The problem is all the content of the new window is overwritten on
the previous window.
Below is the code of the two files

PLEASE help me out ! ! ! !

#1st file
#Klass.py
from Tkinter import *
import AddKlass
class Klass(Frame):
def __init__(self):
self.labels()
self.buttons()
self.menubuttons()
self.scrollandcanvas()
def labels(self):
label1=Label(relief='groove',text=" Class
Id",width=20,anchor=W)
label1.grid(row=0,column=0)
label2=Label(relief='groove',text=" Class
Name",width=20,anchor=W)
label2.grid(row=0,column=1)
label3=Label(relief='groove',text=" Class Room
No.",width=20,anchor=W)
label3.grid(row=0,column=2)
label4=Label(relief='groove',text=" Category
Id",width=80,anchor=W)
label4.grid(row=0,column=3)

def buttons(self):
button1=Button(text="Add",width=10,command=self.Ca llAdd)
button1.grid(row=2,column=5)
button2=Button(text="View",width=10,state=DISABLED )
button2.grid(row=3,column=5)
button3=Button(text="Next",width=10,state=DISABLED )
button3.grid(row=4,column=5)

def menubuttons(self):
menubutton=Menubutton(text="Options",width=10,reli ef="raised")
menubutton.grid(row=5,column=5)
menubutton.menu=Menu(menubutton)
menubutton["menu"]=menubutton.menu
menubutton.menu.add_command(label="Modify")
menubutton.menu.add_command(label="Delete")

def scrollandcanvas(self):
yscroll=Scrollbar()
yscroll.grid(row=1,column=4,rowspan=7,sticky=N+S)
canva=Canvas(bg="#fff",yscrollcommand=yscroll.set)
canva.grid(row=1,column=0,rowspan=7,columnspan=4,s ticky=N+E+S
+W)

def CallAdd(self):
AddKlass.root=Tk()
AddKlass.AddKlas()
AddKlass.root.focus_force()
AddKlass.root.geometry("275x250")
AddKlass.root.title("Add Class Information")
AddKlass.root.resizable(width=False,height=False)
AddKlass.root.mainloop()

root=Tk()
app = Klass()
root.geometry("960x300")
root.title("Class Information")
root.resizable(width=False,height=False)
root.mainloop()


#2nd file
#AddKlass.py
from Tkinter import *

class AddKlas(Frame):
#root=None
def __init__(self):
self.labels()
self.buttons()
self.entry()

def labels(self):
label1=Label(relief='flat',text=" Class
Id :",height=3,width=20)
label1.grid()
label2=Label(relief='flat',text=" Class
Name :",height=3,width=20)
label2.grid()
label3=Label(relief='flat',text=" Class Room
No. :",height=3,width=20)
label3.grid()
label4=Label(relief='flat',text=" Category
Id :",height=3,width=20)
label4.grid()

def buttons(self):
button1=Button(text="Add",width=10,state=DISABLED)
button1.grid(row=5,column=0)
button2=Button(text="Cancel",width=10,command=self .quit)
button2.grid(row=5,column=1)

def entry(self):
entry1=Entry() #by default width =20
entry1.grid(row=0,column=1)
entry2=Entry()
entry2.grid(row=1,column=1)
entry3=Entry()
entry3.grid(row=2,column=1)
entry4=Entry()
entry4.grid(row=3,column=1)

#root=Tk()
#app = AddKlas()
#root.geometry("275x250")
#root.title("Add Class Information")
#root.resizable(width=False,height=False)
#root.mainloop()
Jul 1 '08 #1
1 1737
On Tue, 01 Jul 2008 03:13:42 -0700, viv1tyagi wrote:
Hi everyone ! ! !

I'm just a month old in the world of Python and trying to develop an
application using Tkinter in which a new window pops out on a
particular button press.The code for this new window is in
"AddKlas.py" file.
The problem is all the content of the new window is overwritten on
the previous window.
Below is the code of the two files
There can be only one `Tkinter.Tk` instance per running program. Other
top level windows have to be `Tkinter.Toplevel` instances.

And you should reconsider your usage of classes. You are just abusing
them as containers for functions without using `self` really. And you
should pass the instance of the parent widget as first argument to
constructors of widgets. Otherwise the very first, i.e. the `Tk` instance,
is assumed, which is not true for the widgets that should appear in the
`Toplevel` instance.

Ciao,
Marc 'BlackJack' Rintsch
Jul 1 '08 #2

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

Similar topics

1
by: black | last post by:
Howdy~ I am trying to code with a text editor, during that i got some problems and i hope anyone could supply any clue, they are laied right below:...
1
by: stewart | last post by:
where is the best place to discuss GUI development problems? Thanks!
0
by: Katja Filippova | last post by:
hi, Has anybody tried using natural language toolkit (http://nltk.sourceforge.net/) under Python (my version is 2.1.1)? problems: first, I...
0
by: Svennglenn | last post by:
Hi ! I'm trying to create a graphical program using Tkinter. The program is supposed to save a string the user defines as a filename. I've made...
1
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...
6
by: Claus Tondering | last post by:
My Tkinter application has to receive events from a TCP connection. I have chosen to do this in the following manner: The TCP communication takes...
3
by: Thomas Ploch | last post by:
Hello folks, Since this is my first post on the list, a brief introduction of myself. My name is Thomas, I am 26 years old, I am a student of...
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: ...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.