使用noteb在tkintergui中创建选项卡

2024-05-26 14:20:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Tkinter的图形用户界面,希望图形用户界面有2个标签。我用ttk.notebook来做这个。你知道吗

我的代码如下:

root=tk.Tk()
root.title("Data Tool")
root.geometry("500x300")

nb = ttk.Notebook(root)

nb.place(relx=0,rely=0)

# Adds tab 1 of the notebook
page1 = ttk.Frame(nb)
nb.add(page1, text='Home')

# Adds tab 2 of the notebook
page2 = ttk.Frame(nb)
nb.add(page2, text='Tool')


tk.Label(page1,text="test",bg="red").place(relx=0.2,rely=0.4)

root.mainloop()

此GUI未显示第1页上的标签。代码中可能有什么错误?你知道吗


Tags: 代码textplaceroot标签tool图形用户界面tk

热门问题