473,586 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.menubutton s()
self.scrollandc anvas()
def labels(self):
label1=Label(re lief='groove',t ext=" Class
Id",width=20,an chor=W)
label1.grid(row =0,column=0)
label2=Label(re lief='groove',t ext=" Class
Name",width=20, anchor=W)
label2.grid(row =0,column=1)
label3=Label(re lief='groove',t ext=" Class Room
No.",width=20,a nchor=W)
label3.grid(row =0,column=2)
label4=Label(re lief='groove',t ext=" Category
Id",width=80,an chor=W)
label4.grid(row =0,column=3)

def buttons(self):
button1=Button( text="Add",widt h=10,command=se lf.CallAdd)
button1.grid(ro w=2,column=5)
button2=Button( text="View",wid th=10,state=DIS ABLED)
button2.grid(ro w=3,column=5)
button3=Button( text="Next",wid th=10,state=DIS ABLED)
button3.grid(ro w=4,column=5)

def menubuttons(sel f):
menubutton=Menu button(text="Op tions",width=10 ,relief="raised ")
menubutton.grid (row=5,column=5 )
menubutton.menu =Menu(menubutto n)
menubutton["menu"]=menubutton.men u
menubutton.menu .add_command(la bel="Modify")
menubutton.menu .add_command(la bel="Delete")

def scrollandcanvas (self):
yscroll=Scrollb ar()
yscroll.grid(ro w=1,column=4,ro wspan=7,sticky= N+S)
canva=Canvas(bg ="#fff",yscroll command=yscroll .set)
canva.grid(row= 1,column=0,rows pan=7,columnspa n=4,sticky=N+E+ S
+W)

def CallAdd(self):
AddKlass.root=T k()
AddKlass.AddKla s()
AddKlass.root.f ocus_force()
AddKlass.root.g eometry("275x25 0")
AddKlass.root.t itle("Add Class Information")
AddKlass.root.r esizable(width= False,height=Fa lse)
AddKlass.root.m ainloop()

root=Tk()
app = Klass()
root.geometry(" 960x300")
root.title("Cla ss Information")
root.resizable( width=False,hei ght=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(re lief='flat',tex t=" Class
Id :",height=3,wid th=20)
label1.grid()
label2=Label(re lief='flat',tex t=" Class
Name :",height=3,wid th=20)
label2.grid()
label3=Label(re lief='flat',tex t=" Class Room
No. :",height=3,wid th=20)
label3.grid()
label4=Label(re lief='flat',tex t=" Category
Id :",height=3,wid th=20)
label4.grid()

def buttons(self):
button1=Button( text="Add",widt h=10,state=DISA BLED)
button1.grid(ro w=5,column=0)
button2=Button( text="Cancel",w idth=10,command =self.quit)
button2.grid(ro w=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("Ad d Class Information")
#root.resizable (width=False,he ight=False)
#root.mainloop( )
Jul 1 '08 #1
1 1822
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.Toplev el` 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
1392
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 command can be commonly located at Edit-Undo and Edit-Redo for most of editors. 2 can we communicate with clipboard of current system ? 3 i build a...
1
1356
by: stewart | last post by:
where is the best place to discuss GUI development problems? Thanks!
0
1979
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 manual, but it didn't work: >>> from nltk.token import * Traceback (most recent calls last):
0
1051
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 that's named "Spara ett värde i en sträng till ett filnamn", that's swedish for "Save a value in a string as a file name". The button "Skriv ett...
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...
6
3623
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, I generate an event in the Python application thus: app.event_generate("<<myevent1>>") In the associated event handler, I do this:
3
1974
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 user. :-) Now my problem: I have Tcl/Tk 8.4.4 installed:
1
3173
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). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous...
34
5327
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 "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
0
7841
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...
1
7965
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
8220
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...
0
6617
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...
1
5712
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
5392
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...
1
2345
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
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...

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.