Advertisements

tkinter label frame

Postby thor0298 » Tue Mar 19, 2013 9:36 pm

Offline
thor0298
Posts: 1
Joined: Tue Mar 19, 2013 9:31 pm
I looked at some examples and made a little gui program where you enter a number and it goes into a file and gets some data back.

Right now it prints the data to labelvariable. I want this gui to look more professional, so I was trying get get labelframe to work. When I try to add it in, I click run on pyscriptor and it just hangs.
I can't quite seem to figure out what is wrong.
I attached my original working code


Code: Select all
import Tkinter
from random import Random
file1 = open('survivor.txt')
final=[]
finalnum=[]
##int = 0
x = 0
for lineA in file1:
    final.append(lineA.rstrip() )
file1.close()

while x < len(final):
    finalnum.append(x)
    x = x+1

class simpleapp_tk(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):

        self.grid()

        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)
        self.entryVariable.set(u"Enter Number.")

        button = Tkinter.Button(self,text=u"Randomize!",
                                command=self.OnButtonClick)
        button.grid(column=1,row=0)

        self.labelVariable = Tkinter.StringVar()
        label = Tkinter.Label(self,textvariable=self.labelVariable,
                              anchor="w",fg="white",bg="blue")
        label.grid(column=0,row=1,columnspan=3,sticky='EW')
        self.labelVariable.set(u"Survivors")

        self.grid_columnconfigure(0,weight=1)
        self.resizable(True,False)
        self.update()
##        self.geometry(self.geometry())
        self.geometry('500x100-5+40')

        self.entry.focus_set()
        self.entry.selection_range(0, Tkinter.END)

    def OnButtonClick(self):
        file1 = open('survivor.txt')
        final=[]
        finalnum=[]
##        int = 0
        x = 0
        for lineA in file1:
            final.append(lineA.rstrip() )
        file1.close()

        while x < len(final):
            finalnum.append(x)
            x = x+1

        num = 0
        finalnum = 0
        num =self.entryVariable.get()
        if (float(num) < float((len(final)))):
##            self.labelVariable.set(len(final))
            finalnum = int(num)
            finalsurvivors = []
            Random().shuffle(final)
            for count in range(0,finalnum):
                finalsurvivors.append(final[count])
##            finalsurvivors = final[finalnum]
            self.labelVariable.set(finalsurvivors)

        self.entry.focus_set()
        self.entry.selection_range(0, Tkinter.END)

    def OnPressEnter(self,event):
        file1 = open('survivor.txt')
        final=[]
        finalnum=[]
##        int = 0
        x = 0
        for lineA in file1:
            final.append(lineA.rstrip() )
        file1.close()

        while x < len(final):
            finalnum.append(x)
            x = x+1

        num = 0
        finalnum = 0
        num =self.entryVariable.get()
        if (float(num) < float((len(final)))):
##            self.labelVariable.set(len(final))
            finalnum = int(num)
            finalsurvivors = []
            Random().shuffle(final)
            for count in range(0,finalnum):
                finalsurvivors.append(final[count])
##            finalsurvivors = final[finalnum]
            self.labelVariable.set(finalsurvivors)

        self.entry.focus_set()
        self.entry.selection_range(0, Tkinter.END)


if __name__ == "__main__":
    app = simpleapp_tk(None)
    app.title('Randomizer')
    app.mainloop()