简体   繁体   English

使用笔记本在 Tkinter GUI 中制作标签

[英]Make tabs in Tkinter GUI using notebook

I am trying to make a GUI in Tkinter, want the GUI to have 2 tabs.我正在尝试在 Tkinter 中制作 GUI,希望 GUI 有 2 个选项卡。 I am using ttk.notebook for that.我为此使用ttk.notebook

My code is as follows:我的代码如下:

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

This GUI is not showing the label on page1.此 GUI 未在第 1 页显示 label。 What could be wrong in the code?代码中可能有什么问题?

Your label's master is set to page1 which is an empty frame, and then you call place on the label using relx and rely .您的标签的 master 设置为page1这是一个空框架,然后您使用relx和 trust 在rely上调用place To show the widget, your frame need to have a size:要显示小部件,您的框架需要有一个大小:

page1 = ttk.Frame(nb,height=400,width=400)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM