473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1805
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 how can we undo and redo action ? This...
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 wanted to import a module, as it is written in the...
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 it work with the the first button in the program...
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 the following problems, probably all related, that...
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 place in a separate thread. When I receive data,...
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 Computational Linguistics and I am a python...
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 (the only things it imports are sys and socket)....
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: Traceback (most recent call last): File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.