使用可实现多页切换,直接对中文正楷进行编码。请点击微软雅荷。请点击微软雅荷。人生苦短。我使用左上角的小图标来设置窗口不可变。
Ttk。笔记本可以用来实现多页切换。
直接装载代码:
将tkinter作为tkfrom tkinter导入ttkfrom tkinter导入ENDclass App: def __init__(self,master): self.notebook = ttk。笔记本(主)self.frame1 = tk。Frame(主)self.frame2 = tk。frame(master)self . label = tk . label(self . frame 1,text = "Python ",font =("中文正楷",12))self . label . grid()self . entry 1 = tk . entry(self . frame 1,Width = 35)self . entry 1 . grid(row = 0,column = 1)self . bu1 = tk . button(self . frame 1,text = "please click 1 ",Command = self . bu1 . grid(row = 0,column = 2)self . list 1 = tk . listbox(self command = self . bu2)self . bu2 . grid()self . list 2 = tk . listbox(self . frame 2,font =("微软雅黑",12),width = 38,Heigh = 8) self.list2.grid (row = 1,column span = 5)self . notebook . add(self . frame 1,text = " test1 ")self . notebook . add(self . frame 2,text = " test2 ")self . notebook . pack(padx = 10,pady=5,fill=tk。 BOTH,expand = True)def bu1(self):self . list 1 . insert(END,Self.entry1.get()+"人生苦短,我用Python ")self . list 1 . see(END)self . list 1 . update()def bu2(self):self . list 2 . insert(END," Python让我更强!")self . list 2 . see(END)self . list 2 . update()if _ _ name _ _ = = " _ _ main _ _ ":root = tk。tk()root . title(" notebook _ test ")# root . icon bitmap(" fa . ico ")#设置小图标root . geometry(" 400 x20小编20小编100 ")# root . resizable(0,0) #设置窗口不可变App(root) root.mainloop()
评论前必须登录!
注册