2022年11月17日 星期四

Python GUI 配置管理員pack() EX3.21 , 3.22 , 3.23

 # ch3_21.py

from tkinter import *


root = Tk()

root.title("ch3_21")               # 視窗標題

root.geometry("300x200")

    

Label(root,text='Mississippi',bg='red',fg='white',

      font='Times 24 bold').pack(fill=X)  

Label(root,text='Kentucky',bg='green',fg='white',

      font='Arial 24 bold italic').pack(fill=BOTH,expand=True)  

Label(root,text='Purdue',bg='blue',fg='white',

      font='Times 24 bold').pack(fill=X)  


root.mainloop() 


# ch3_22.py

from tkinter import *


root = Tk()

root.title("ch3_22")               # 視窗標題

    

Label(root,text='Mississippi',bg='red',fg='white',

      font='Times 20 bold').pack(side=LEFT,fill=Y)  

Label(root,text='Kentucky',bg='green',fg='white',

      font='Arial 20 bold italic').pack(side=LEFT,fill=BOTH,expand=True)  

Label(root,text='Purdue',bg='blue',fg='white',

      font='Times 20 bold').pack(side=LEFT,fill=Y)  


root.mainloop() 


# ch3_23.py

from tkinter import *


root = Tk()

root.title("ch3_23")

root.geometry("300x180")            # 設定視窗勘寬300高180

print("執行前",root.pack_slaves())

oklabel=Label(root,text="OK",       # 標籤內容是OK

              font="Times 20 bold", # Times字型20粗體

              fg="white",bg="blue") # 藍底白字

oklabel.pack(anchor=S,side=RIGHT,   # 從右開始在南方配置

             padx=10,pady=10)       # x和y軸間距皆是10

nolabel=Label(root,text="NO",       # 標籤內容是OK

              font="Times 20 bold", # Times字型20粗體

              fg="white",bg="red")  # 藍底白字

nolabel.pack(anchor=S,side=RIGHT,   # 從右開始在南方配置

             pady=10)               # y軸間距皆是10

print("執行後",root.pack_slaves())


root.mainloop()



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...