probelm with Tkinter module

David Cruz dcruz at bpo.hp.com
Fri Aug 9 10:59:44 CEST 2002


Hi everybody,

I'm using the Tkinter module to create an interface with python but I
have some problems that I can 't resolve.
I've created an interface with  a button; when I click on this buttons a
new window must appear;this new window contains other buttons and a text
field; but my problem is that when I launch the application,  appear the
main interface(normal) and a second empty window( which is the window
associated to the buttons) ; when I click on the button(execute a
"grid" command), the buttons and the text field appear in the empty
window;
Somebody could tell me how can Ido to not have this empty window when
Iaunch my application.

Thanks

Here is my program:


from Tkinter import *


class OutputRollerTests(Frame):
     def __init__(self,root):
          Frame.__init__(self,root)
          self.moveTest = Button(self,text=" move
roller",width=20,command=root.addMoveScript)
          self.collectTest = Button(self,text="collect datas", width=20,
command=root.addCollectScript)

     def displayon(self):
          self.grid()
          self.moveTest.grid( column = 0, sticky = NW)
          self.collectTest.grid(colum = 0, sticky = NW)


class OutputRollerFrame(Frame):
     def __init__(self,root):
          Frame.__init__(self,root)
          self.script=Text(self,width=70,bg="white")
          self.listElts=OutputRollerTests(self)
          self.grid_forget()
          self.okButton = Button(self,text="ok", width=10)
          self.quitButton = Button(self,text="quit", width=10,
command=self.grid_forget)

     def displayon(self):
          self.script.grid(column=1, row=1, rowspan=2, sticky = NE)
          self.listElts.displayon()
          self.listElts.grid(column=0, row=1, sticky = NW)
          self.quitButton.grid(column=1,row=3, sticky = SE)
          self.okButton.grid(column=1,row=3, sticky = SW)
          self.grid()


     def addMoveScript(self):

self.script.insert(END,"dist=Distance(3,1)\nspeed=Speed(1,1)\nmode=PythonControlledMotor.IControlledMotor.POSITION_ACCURATE\nOutputRollerMotor.move(dist,
speed,  mode)\n")

     def addCollectScript(self):
          self.script.insert(END,"TODO\n")


class PaperMotorTests(Frame):
     def __init__(self,root):
          Frame.__init__(self,root)
          self.moveTest = Button(self,text=" move roller",width=20,
anchor=NW,command=root.addMoveScript)
          self.collectTest = Button(self,text="collect datas", width=20,
anchor=NW,command=root.addCollectScript)
          self.grid_forget()

     def getlist(self):
          return PaperMotorTests

     def displayon(self):
          self.grid()
          self.moveTest.grid( column = 0, sticky = NW)
          self.collectTest.grid(colum = 0, sticky = NW)



class PaperMotorFrame(Frame):
     def __init__(self,root):
          Frame.__init__(self,root)
          self.script=Text(self,width=40,bg="white")
          self.listElts=PaperMotorTests(self)
          self.okButton = Button(self,text="ok", width=10)
          self.quitButton = Button(self,text="quit", width=10,
command=self.quit)
          self.grid_forget()

     def displayon(self):
          self.script.grid(column=1, row=1, rowspan=2, sticky = NE)
          self.listElts.displayon()
          self.listElts.grid(column=0, row=1, sticky = NW)
          self.quitButton.grid(column=1,row=2, sticky = SE)
          self.okButton.grid(column=1,row=2, sticky = SW)
          self.grid()


     def addMoveScript(self):

self.script.insert(END,"dist=Distance(3,1)\nspeed=Speed(1,1)\nmode=PythonControlledMotor.IControlledMotor.POSITION_ACCURATE\nOutputRollerMotor.move(dist,
speed, mode)\n")

     def addCollectScript(self):
          self.script.insert(END,"TODO\n")

class ListModule(Frame):
        def __init__(self,root):
                Frame.__init__(self,root)
                self.grid()
                outputRollerWindow = OutputRollerFrame(root=Tk())
                paperMotorWindow = PaperMotorFrame(root=Tk())
                self.outputRollerMotorButton = Button(self,text="
outputRollerMotor",width=20,command=outputRollerWindow.displayon)
                self.outputRollerMotorButton.grid( column = 0, sticky =
NW)
                self.paperMotorButton = Button(self,text="paperMotor",
width=20, command=paperMotorWindow.displayon)
                self.paperMotorButton.grid(colum = 0, sticky = NW)

class MainFrame(Frame):
        def __init__(self,root):
                Frame.__init__(self,root)
#               self.config(height=600,width=400)
#               self.grid_propagate(0)
                #self.pack()
                self.title=Label(self,text="PYTHON SCRIPT GENERATION",
width=80);
                self.title.grid(row=0, sticky = N)
                self.script=Text(self,height=30,width=50,bg="white")
                self.script.grid(row=2, rowspan=2, sticky = NE)
                self.listElts=ListModule(self)
                self.listElts.grid(column=0, row=2, sticky = NW)
                self.grid()

        def pressb1(self):
                self.script.insert(END,"hello world\n")

        def loop(self):
                self.mainloop()

root= Tk()
main = MainFrame(root)
main.grid()
main.loop()





More information about the Python-list mailing list