473,706 Members | 2,427 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
from Tkinter import *
import AddKlass
class Klass(Frame):
def __init__(self):
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

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()

app = Klass()
root.geometry(" 960x300")
root.title("Cla ss Information")
root.resizable( width=False,hei ght=False)

#2nd file
from Tkinter import *

class AddKlas(Frame):
def __init__(self):

def labels(self):
label1=Label(re lief='flat',tex t=" Class
Id :",height=3,wid th=20)
label2=Label(re lief='flat',tex t=" Class
Name :",height=3,wid th=20)
label3=Label(re lief='flat',tex t=" Class Room
No. :",height=3,wid th=20)
label4=Label(re lief='flat',tex t=" Category
Id :",height=3,wid th=20)

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.grid(row =1,column=1)
entry3.grid(row =2,column=1)
entry4.grid(row =3,column=1)

#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 1831
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.

Marc 'BlackJack' Rintsch
Jul 1 '08 #2

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

Similar topics

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 textfield by Text class of Tkinter module. i found some shortcut keys are automatically activated but they...
by: stewart | last post by:
where is the best place to discuss GUI development problems? Thanks!
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):
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 värde till filen" (swedish for "Write a value to the file")
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?
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:
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:
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 versions of Freeze used a pretty simple-minded algorithm to
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
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,...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
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,...
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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...
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.