Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีอัปเดตข้อมูลใน Grid ของ Tkinter


สมมติว่าแอปพลิเคชัน Tkinter มี widget วางในหน้าต่างด้วย Grid Geometry Manager เพื่อเปลี่ยนคุณสมบัติของ Widget ให้ใช้เมธอด configure(**options) ในการแสดง widget เราต้องกำหนดคอนสตรัคเตอร์ให้กับตัวแปร เพื่อเข้าถึงเปลี่ยนคุณสมบัติของ widget ได้ทั่วไป

ตัวอย่าง

# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")

# Add a Label widget and assign it to a new variable
label=Label(win, text="This is Houstan Control. " "We've detected a new Mission", background="skyblue", font=('Aerial 11'))
label.grid(row=0, column=2)
win.mainloop()

ผลลัพธ์

การรันโค้ดจะแสดงหน้าต่างที่มี Label widget จัดชิดซ้ายสุด

วิธีอัปเดตข้อมูลใน Grid ของ Tkinter