本章內(nèi)容,生成一個如下的小界面,一只可愛的加菲貓! 代碼如下: import tkinter as tk root = tk.Tk() textLable = tk.Label(root,text='這是一只好玩的貓!') textLable.pack(side=tk.LEFT) photo = tk.PhotoImage(file = 'C:\\Users\\MR-Wang\\Desktop\\jiafei.gif') imgLable = tk.Label(root,image=photo) imgLable.pack(side=tk.RIGHT) root.mainloop() 代碼講解import tkinter as tk root = tk.Tk() 導(dǎo)入tkinter庫,并創(chuàng)建根界面root textLable = tk.Label(root,text='這是一只好玩的貓!') imgLabel = tk.Label(root,image=photo) 創(chuàng)建類Label的兩個對象textLabel和imgLabel pack()函數(shù),是Label對象的位置和布局 root.mainloop()進(jìn)入主循環(huán) |
|