2022年11月17日 星期四

Python GUI 配置管理員pack() EX3.35 , 3.35.1 , 3.35.2 , 3.35.3

 # ch3_35.py

from tkinter import *

root = Tk()

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

Colors = ["red","orange","yellow","green","blue","purple"]


r = 0                               # row編號

for color in Colors:

    Label(root,text=color,relief="groove",width=20).grid(row=r,column=0)

    Label(root,bg=color,relief="ridge",width=20).grid(row=r,column=1)

    r += 1


root.mainloop()


# ch3_35_1.py

from tkinter import *


root = Tk()

root.title("ch3_35_1")


root.rowconfigure(1, weight=1)

root.columnconfigure(0, weight=1)


lab1 = Label(root,text="Label 1",bg="pink")

lab1.grid(row=0,column=0,padx=5,pady=5)


lab2 = Label(root,text="Label 2",bg="lightblue")

lab2.grid(row=0,column=1,padx=5,pady=5)


lab3 = Label(root,bg="yellow")

lab3.grid(row=1,column=0,columnspan=2,padx=5,pady=5)


root.mainloop()


# ch3_35_2.py

from tkinter import *


root = Tk()

root.title("ch3_35_2")


root.rowconfigure(1, weight=1)

root.columnconfigure(0, weight=1)


lab1 = Label(root,text="Label 1",bg="pink")

lab1.grid(row=0,column=0,padx=5,pady=5,stick=W)


lab2 = Label(root,text="Label 2",bg="lightblue")

lab2.grid(row=0,column=1,padx=5,pady=5)


lab3 = Label(root,bg="yellow")

lab3.grid(row=1,column=0,columnspan=2,padx=5,pady=5,

          sticky=N+S+W+E)


root.mainloop()


# ch3_35_3.py

from tkinter import *


root = Tk()

root.title("ch3_35_3")


root.rowconfigure(1, weight=1)

root.columnconfigure(0, weight=1)


lab1 = Label(root,text="Label 1",bg="pink")

lab1.grid(row=0,column=0,padx=5,pady=5,stick=W+E)


lab2 = Label(root,text="Label 2",bg="lightblue")

lab2.grid(row=0,column=1,padx=5,pady=5)


lab3 = Label(root,bg="yellow")

lab3.grid(row=1,column=0,columnspan=2,padx=5,pady=5,

          sticky=N+S+W+E)


root.mainloop()



沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...