2016-01-30 58 views
0

我有這個代碼,但這只是系統非常長的代碼的一部分。問題是,我試圖創建一個標題邊框,但沒有出現。我不知道什麼是錯誤。標題邊界Tkinter - 沒有出現

from Tkinter import * 
def onclick(): 
    pass 

import tkMessageBox 


root = Tk() 

root.title("Pantai Hospital") 
root.geometry("200x200") 

Label(root, text = "Welcome to Pantai Hospital!").grid() 

#the problem starts here 
f1 = Frame(root, width = 300, height = 110) 
f2 = Frame(f1, relief = GROOVE, borderwidth = 2) 


l9 = Label(f2, text = "Choose your specialist:") 
l9.pack(pady = 10) 

specialistchoose = IntVar() 
r1 = Radiobutton (f2, text = "Cardiology", variable = specialistchoose, value = 1) 
r1.grid(row = 1, column = 0) 
r2 = Radiobutton (f2, text = "Gastroenterology", variable = specialistchoose, value = 2) 
r2.grid(row = 1, column = 1) 
r3 = Radiobutton (f2, text = "Dermatology", variable = specialistchoose, value = 3) 
r3.grid (row = 1, column = 2) 
r4 = Radiobutton (f2, text = "Psychiatry", variable = specialistchoose, value = 4) 
r4.grid (row = 3, column = 0) 
r5 = Radiobutton (f2, text = "Dentist", variable = specialistchoose, value = 5) 
r5.grid(row = 3, column = 1) 
f2.place(relx = 0.01, rely = 0.125, anchor = NW) 
Label(f1, text = "Specialist:").place(relx = .06, rely = 0.125, anchor = W) 
f1.pack() 
root.mainloop() 

沒有人有任何想法如何克服這個?謝謝:)

+0

您可以創建一個期望的結果圖像? – furas

+0

我運行您的代碼,並收到錯誤消息。下次在console/terminal/cmd.exe中檢查您的代碼並添加完整的錯誤消息。 – furas

回答

1

問題是因爲你混合grid()pack(),你會得到錯誤信息。

不要在相同的Frame(或Window)中使用grid()pack()。但是,您仍然可以在另一個Frame中使用grid()中的一個Framepack()(另一個幀甚至可以在第一幀內)。

所以請再試一次。


編輯:LabelFrame其中提請bordertitle。您可以使用它而不是FrameLabel

from Tkinter import * 

root = Tk() 
root.title("Pantai Hospital") 

# in main window I use only `pack` 

l = Label(root, text="Welcome to Pantai Hospital!") 
l.pack() 

lf = LabelFrame(root, text="Specialist:") 
lf.pack() 

# inside LabelFrame I use only `grid` 

t = Label(lf, text="Choose your specialist:") 
t.grid(columnspan=2, stick='w') 

specialistchoose = IntVar() 

r1 = Radiobutton(lf, text="Cardiology", variable=specialistchoose, value=1) 
r1.grid(row=1, column=0, stick='w') 

r2 = Radiobutton(lf, text="Gastroenterology", variable=specialistchoose, value=2) 
r2.grid(row=1, column=1, stick='w') 

r3 = Radiobutton(lf, text="Dermatology", variable=specialistchoose, value=3) 
r3.grid(row=1, column=2, stick='w') 

r4 = Radiobutton(lf, text="Psychiatry", variable=specialistchoose, value=4) 
r4.grid(row=2, column=0, stick='w') 

r5 = Radiobutton(lf, text="Dentist", variable=specialistchoose, value=5) 
r5.grid(row=2, column=1, stick='w') 


root.mainloop() 

enter image description here

+0

沒有錯誤信息。但我現在明白了。非常感謝你!我欣賞它:) –

+0

看到代碼和圖像在答案 – furas

+0

我明白了。好吧,我現在明白了,謝謝! –