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()



沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...