So! I'm building a GUI for an application I'm currently developing and I'm having a bit of trouble figuring out an issue. I'll try to explain it as best as I can in the code lines. Basically, I built a class to handle the initial window for the program, but if you read the code to the last line (I've snipped some of the code to get to the point), what I'm trying to do is mimic the first class I built so it shows a whole new window with the input, button, and text fields, as well as the labels. However, it never turns out quite right and the labels never print to the new tkinter window? Thoughts on how to put a class inside a class to do the same thing spkgui_tk(Tkinter.Tk) does?
Thanks ahead of time! If you have questions, just let me know! :)
import Tkinter
from fabric.api import *
class spkgui_tk(Tkinter.Tk):
'''Builds the shell for the program'''
def __init__(self, parent):
Tkinter.Tk.__init__(self, parent)
self.parent = parent
self.initialize()
def initialize(self):
# main gui window
self.grid()
# default stdout text field
stdout = Tkinter.Text(self, autoseparators=True, height=10, width=50, wrap=Tkinter.WORD)
stdout.grid(column=0, row= 15, padx=10, pady=10, sticky="EW", columnspan=2,rowspan=2)
_inittext_ = "Welcome to the best damn program manager on the planet!"
stdout.insert(Tkinter.END, _inittext_)
stdout.see(Tkinter.END)
# entry fields
self.entryVariable = Tkinter.StringVar()
self.entry = Tkinter.Entry(self, textvariable = self.entryVariable)
self.entry.grid(column=0, row=0, sticky="EW")
self.entry.bind("<Return>", self.OnPressEnter) #bound to return, calls OnPressEnter method
self.entryVariable.set(u"Choose an option.")
# buttons (maybe change the font and the size later?)
button = Tkinter.Button(self, text="Exit",command=self.OnButtonClick, width=15)
button.grid(column=1,row=0)
# labels
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self, textvariable = self.labelVariable, anchor = "w", fg="white", bg= "grey")
label.grid(column=0, row=1, columnspan = 2, sticky = "EW")
self.labelVariable.set(u"1. Erase")
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self, textvariable = self.labelVariable, anchor = "w", fg="black", bg = "white")
label.grid(column=0, row=2, columnspan = 2, sticky = "EW")
self.labelVariable.set(u"2. Echo Path")
<--snipped-->
self.grid_columnconfigure(0, weight=1)
self.resizable(True,False)
self.update()
self.geometry(self.geometry())
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def OnButtonClick(self):
self.destroy()
#### On Press Enter (from self window) ######
def OnPressEnter(self, event):
catch_command = int(self.entryVariable.get())
catch_command = int(self.entryVariable.get())
if catch_command == 1:
erase()
stdout = Tkinter.Text(self, autoseparators=True, height=10, width=50, wrap=Tkinter.WORD)
stdout.grid(column=0, row= 15, padx=10, pady=10, sticky="EW", columnspan=2,rowspan=2)
stext = "Erases bits and pieces from your trash can."
stdout.insert(Tkinter.END, stext)
stdout.see(Tkinter.END)
<--snipped-->
if catch_command == 3:
the problem in question. :/