Python 标题边框Tkinter-未出现

Python 标题边框Tkinter-未出现,python,user-interface,tkinter,Python,User Interface,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!").gr

我有这个代码,但这只是一个很长的系统代码的一部分。问题是,我试图创建一个有标题的边框,但它没有出现。我不知道是什么错误

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

有人知道怎么做吗?谢谢:)

问题是因为您将
grid()
pack()
混合使用,会收到错误消息

不要在同一个
框架
(或
窗口
)中使用
grid()
pack()
)。但您仍然可以在一个
帧中使用
grid()
,在另一个
帧中使用
pack()
(另一个帧甚至可以在第一个帧中)

所以再试一次


编辑:有一个
LabelFrame
可以绘制
边框
标题
。您可以使用它代替
框架
标签

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

您能否创建具有预期结果的图像?我运行了您的代码,收到了错误消息。下次检查console/terminal/cmd.exe中的代码并添加完整的错误消息。没有错误消息。但我现在明白了。非常感谢你!我很感激:)