[Discuss] Python question using tkinter LabelFrame widget (SOLVED)
Jerry Feldman
gaf at blu.org
Thu Sep 12 09:10:49 EDT 2013
This was pretty obvious.
In initialize, add:
self.mainWindow = Tkinter.Tk()
Then make mainWindow the parent of the LabelFrame.
radios =
Tkinter.LabelFrame(self.mainWindow,borderwidth=10,text="Commands")
On 09/04/2013 03:10 PM, Jerry Feldman wrote:
> I have a couple of tcl/tk scripts I want to convert to Python for a
> couple of reasons:
> 1. Python is a better programming language than tcl.
> 2. Noone else in my group knows tcl/tk
> 3. One of the products that the tcl/tk application interfaces with
> uses Python for its installerand I can clean up the interface.
> The only issue I have at the moment is using the LabelFrame widget. In
> one of the applications, I am using a tcl/tk labelframe and it works
> fine, but not in Python. I don't have to use the LabelFrame but it
> separates these radio buttonsfrom text boxes later on in the
> application. I've tried things like adding columnconfigure(), but that
> had no effect.
> #!/usr/bin/python
>
> import Tkinter
>
>
> # define
> class lfex_tk(Tkinter.Tk):
> def __init__(self,parent):
> Tkinter.Tk.__init__(self,parent)
> self.parent = parent
> self.initialize()
>
> def initialize(self):
> self.grid()
>
> self.command = Tkinter.StringVar()
> self.entry =
> Tkinter.Entry(self,width=60,textvariable=self.command)
> self.entry.grid(column=0,row=0,sticky='EW')
> self.command.set(u"Enter data")
>
>
> ### define buttons
> run = Tkinter.Button(self,text=u"data",
> command=self.OnRunButtonClick)
> self.labelVariable = Tkinter.StringVar()
> kwit = Tkinter.Button(self,text=u"Quit",
> command=self.OnQuitButtonClick)
>
> ### Set up the grids for row 0
> run.grid(column=1,row=0)
> kwit.grid(column=6,row=0, sticky='E')
>
> self.resizable(True, True)
> self.update()
> self.geometry(self.geometry())
> self.entry.focus_set()
> self.entry.selection_range(0, Tkinter.END)
>
> radios = Tkinter.LabelFrame(self,borderwidth=10,text="Commands")
> radios.grid(column=0,row=3, padx=5, pady=5)
> whichCMD = Tkinter.StringVar()
> radios.one = Tkinter.Radiobutton(radios, text="One",
> variable=whichCMD, value="One")
> radios.two = Tkinter.Radiobutton(radios, text="Two",
> variable=whichCMD, value="Two")
> radios.three= Tkinter.Radiobutton(radios, text="Three",
> variable=whichCMD, value="Three")
> ## Default to radio button 1
> radios.one.select()
> self.update()
>
>
> ## Button Actions
> def OnQuitButtonClick(self):
> app.destroy()
>
> def OnRunButtonClick(self):
> # does nothing for this example
> self.entry.focus_set()
> self.entry.selection_range(0, Tkinter.END)
>
>
> if __name__ == "__main__":
> app = lfex_tk(None)
> app.title('LabelFrameTest')
> app.mainloop()
>
--
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66 C0AF 7CEA 30FC 3BC1 EB90
More information about the Discuss
mailing list