2013-09-30 2 views
1

저는 Python 및 ttk에 어려움을 겪고 있습니다. 올바르게 작동하는 UI를 만들었지 만 조금 어색해 보입니다. 패딩을 추가하고 크기 조정 등을 할 수 있도록 프레임을 추가하고 싶었지만 지금은 위젯이 전혀 표시되지 않습니다. 내 코드는 아래와 같습니다.프레임의 ttk 위젯이 표시되지 않습니다.

이전에는 parent을 위젯의 부모로 전달했는데, 이는 작동했습니다. 나는 몇 가지 튜토리얼을 통해 작업 해왔고 분명히 잘못된 것을 볼 수는 없다.

class Application: 

    def __init__(self, parent): 
     self.parent = parent 

     self.content = ttk.Frame(parent, padding=(3,3,12,12)) 
     self.content.columnconfigure(1, weight=1) 
     self.content.rowconfigure(1, weight=1) 

     self.row1() 


    def row1(self): 
     self.enButton = ttk.Button(self.content, text="Enable", command=self.enableCmd) 
     self.disButton = ttk.Button(self.content, text="Disable", command=self.disableCmd) 
     self.enButton.grid(column=1, row=1) 
     self.disButton.grid(column=2, row=1) 
     self.disButton.state(['disabled']) 

    def enableCmd(self): 
     self.disButton.state(['!disabled']) 
     self.enButton.state(['disabled']) 
     self.ser.write("pe001\n") 



if __name__ == '__main__': 
    root = Tk() 
    root.title("PC Control Interface") 
    img = Image("photo", file="appicon.gif") 
    root.tk.call('wm','iconphoto',root._w,img) 

    app = Application(root) 

    root.mainloop() 

답변

0

콘텐츠 프레임을 부모로 묶거나 그리드하면됩니다.

또한 게시 할 코드를 추가 할 필요없이 다른 사람이 실행할 수 있으면 도움이됩니다. 다음 코드로 끝났습니다.

import Tkinter as tk 
import ttk 

#from PIL import Image 

class Application: 

    def __init__(self, parent): 
     self.parent = parent 

     self.content = ttk.Frame(parent, padding=(3,3,12,12)) 
     self.content.pack() 
     self.content.columnconfigure(1, weight=1) 
     self.content.rowconfigure(1, weight=1) 

     self.row1() 


    def row1(self): 
     self.enButton = ttk.Button(self.content, text="Enable", command=self.enableCmd) 
     self.disButton = ttk.Button(self.content, text="Disable", command=self.disableCmd) 
     self.enButton.grid(column=1, row=1) 
     self.disButton.grid(column=2, row=1) 
     self.disButton.state(['disabled']) 

    def enableCmd(self): 
     self.disButton.state(['!disabled']) 
     self.enButton.state(['disabled']) 
     # self.ser.write("pe001\n") 

    def disableCmd(self): 
     self.disButton.state(['disabled']) 
     self.enButton.state(['!disabled']) 


if __name__ == '__main__': 
    root = tk.Tk() 
    root.title("PC Control Interface") 
    #img = Image("photo", file="T.ico") # "appicon.gif" 
    #root.tk.call('wm','iconphoto',root._w,img) 

    app = Application(root) 

    root.mainloop()