2016-06-14 5 views
0

안녕하세요 저는 프로그래밍에 익숙하지 않으며 분명한 실수가 있으면 사과드립니다. 저는 Mac OSX El Capitan에서 python 3.5를 사용하여 tkinter에 GUI를 작성하고 있습니다. 나는이 프로그램이 메인 루프를 입력 실행하면python3 tkinter gui 응답이 없습니다

from tkinter import * 
from tkinter import ttk 



class GUI(object): 
    def __init__(self, master): 
     master.title("Title") 
     master.resizable(False, False) 
     self.frame1 = ttk.Frame(master) 
     self.frame1.pack() 

     ttk.Label(text="Organism").grid(row=1, column=0) 

     self.organism_picker = ttk.Combobox(self.frame1, values=("Drosophila  melanogaster", 
                  "Danio rerio", 
                  "Caenorhabditis  elegans", 
                  "Rattus  norvegicus", 
                  "Mus musculus", 
                  "Homo sapiens")) 
     self.organism_picker.grid(row=2, column=0) 

     ttk.Label(text="Core gene symbol:").grid(row=3, column=0) 

     self.core = ttk.Entry(self.frame1) 
     self.core.grid(row=4, column=0) 


root = Tk() 
gui = GUI(root) 
root.mainloop() 

하지만, GUI 윈도우는 결코 나타나지 않습니다 및 실행 프로그램은 reponding되지 않은 : 여기에 지금까지 코드입니다. Python 3을 다시 설치하려고 시도했는데 ActiveTcl을 설치했지만 ActivePython을 대신 사용해 보았습니다. 그것의 아무도는 작동하지 않았다.

답장을 보내 주셔서 감사합니다.

답변

1

코드 유일한 문제는 당신이 에 잊고 있다는 것입니다 첨부 할 두 개의 레이블을 주요 위젯 self.frame1에.

가, 그 문제를 해결 다음과 같이이를 수정하려면 그 일을 한 후

#Attach the 2 labels to self.frame1 
ttk.Label(self.frame1,text="Organism").grid(row=1, column=0) 
ttk.Label(self.frame1,text="Core gene symbol:").grid(row=3, column=0) 

데모

, 당신이 얻을 것이다 :

enter image description here

3

는이 오류를 지적로 Geometry 관리자 충돌 생성과 같이 팩()와 그리드()를 사용하지 않아야합니다 :

self.frame1.pack() 

에 :

_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack 

을 변경하려고

self.frame1.grid() 

이 경우 상당히 간단한 레이아웃이므로 전체적으로 팩을 사용하는 것이 좋습니다. this guide를 참조하십시오 드디어

When to use the Pack Manager

Compared to the grid manager, the pack manager is somewhat limited, but it’s much easier to use in a few, but quite common situations:

Put a widget inside a frame (or any other container widget), and have it fill the entire frame Place a number of widgets on top of each other Place a number of widgets side by side

과를 :

Note: Don’t mix grid and pack in the same master window. Tkinter will happily spend the rest of your lifetime trying to negotiate a solution that both managers are happy with. Instead of waiting, kill the application, and take another look at your code. A common mistake is to use the wrong parent for some of the widgets.