python tkinter 創建頁簽界面


為python tkinter界面創建分頁欄。
需要使用Notebook()和Frame()。
使用Notebook()創建分頁欄,Frame()創建多個框架來當做不同的頁面。


import matplotlib.pyplot as plt
from tkinter import *
import tkinter.ttk as ttk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
root = Tk()
root.title('測試')

root.geometry('1600x1000+10+10')

tab_main=ttk.Notebook()#創建分頁欄
tab_main.place(relx=0.02, rely=0.02, relwidth=0.887, relheight=0.876)

tab1=Frame(tab_main)#創建第一頁框架

tab1.place(x=0,y=30)
tab_main.add(tab1,text='第一頁')#將第一頁插入分頁欄中

Text = Text(tab1,width = 50,height=40)#顯示文本框
Text.place(x=10,y=100)
button = Button(tab1,text='1',width=5)
button.place(x=50,y=10)
button1 = Button(tab1,text='2',width=5)
button1.place(x=100,y=10)
button2 = Button(tab1,text='3',width=5)
button2.place(x=150,y=10)
button3 = Button(tab1,text='4',width=5)
button3.place(x=200,y=10)

 

tab2=Frame(tab_main)
tab2.place(x=100,y=30)
tab_main.add(tab2,text='第二頁')
fig = plt.figure(figsize=(7,4),dpi=100)#圖像比例
f_plot =fig.add_subplot(111)#划分區域
canvas_spice = FigureCanvasTkAgg(fig,tab2)
canvas_spice.get_tk_widget().place(relx=0.3,rely=0.1)#放置位置

 

root.mainloop()

 

 

 

 

 


版權聲明:本文為CSDN博主「印度飛餅不會飛」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/WuHuqifei2020/article/details/106944877/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM