2016-06-14 21 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に 2つのラベルを付けるにに忘れてしまったということです。

、それを修正し、次のようにそれらを変更するには:

enter image description here

#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) 

デモ

ことをやった後、あなたはこれを取得します

3

これは、このエラーで指摘したように、ジオメトリマネージャの競合が生成されますようあなたがパック()とグリッドを()を使用しないでください。

self.frame1.pack() 

へ:

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

を変更してみてください

self.frame1.grid() 

このケースでは、これはかなり単純なレイアウトなので、pack overallを使用することをおすすめします。 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.

関連する問題