[Tutor] Tkinter troubles
btkuhn at email.unc.edu
btkuhn at email.unc.edu
Mon Nov 3 04:33:20 CET 2008
Hi guys,
I'm having trouble with weird activity with a Tkinter GUI I'm
creating. I've stripped down the code somewhat to simplify the
problem somewhat, and I've posted it below, with further explanation
at the end of this message:
from Tkinter import *
import tkFileDialog,tkSimpleDialog
WINDOWWIDTH=500
WINDOWHEIGHT=500
class App:
def __init__ (self,master):
self.window = Frame(master)
self.window.pack()
self.master= master
#Create frame to contain all others
self.display=Frame(self.window,width=WINDOWWIDTH,height=WINDOWHEIGHT,
bg='black')
self.display.pack()
self.addMenu(self.master)
#Create widgets
self.createwidgets()
def createwidgets(self):
self.leftframe=Frame(self.display,
width=WINDOWWIDTH/3,height=WINDOWHEIGHT, bg='white')
self.rightframe=Frame(self.display,
width=2*WINDOWWIDTH/3,height=WINDOWHEIGHT, bg='blue')
self.leftframe.pack(side="left", expand="yes", fill="x")
self.rightframe.pack(side="left", expand="yes", fill="x")
def displayStories(self):
self.lb = Text(self.leftframe)
self.lb.pack()
def addMenu(self,master):
self.menu = Menu(self.window)
master.config(menu=self.menu)
self.feedmenu = Menu(self.menu)
self.menu.add_cascade(label="RSS", menu=self.feedmenu)
self.feedmenu.add_command(label="Load RSS",
command=self.displayStories)
root=Tk()
app=App(root)
root.mainloop()
:
Basically I'm trying to create 2 columns on the page so that
(eventually) I will be able to have sepearte text boxes in each
column. The code so far creates a leftframe and rightframe, with
parent frame self.display . When I run the script this happens as
expected.
But next, I want to create a text box within self.leftframe which is
done in function displayStories . self.lb is created with parent
self.leftframe . When this is run, the text box shows up, but my
layout goes to hell. I want the text box to be contained within
self.leftframe, but when it is added self.leftframe disappears (or is
completely filled by the text box), the dimensions that I had
specified for self.leftframe and self.rightframe are forgotten about,
and I can see self.display (black background) on the part of the
screen in the left frame that is not filled by the text box. This
makes a lot more sense if you run the simple script I've posted.
I've tried adjusting various options, and also using the "grid"
manager instead of "pack", but I can't seem to figure out why this is
happening. Can anyone help out?
Thanks,
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081102/80f194bc/attachment.htm>
More information about the Tutor
mailing list