ทดสอบโดยโจย์จากหนังสือ Exploring Python
try changing the size of the buttons in the hello world program using the options width=n and height=n. what is the effect?
the description of the slide widget show how to make the componentas wide as the window using the argument pad=X with the pack command.
what happens if you do this with a button?
การลองปรับเปลี่ยนขนาดปุ่ม และ pack command
โค้ด: เลือกทั้งหมด
from tkinter import *
def mhello():
print("mindphp")
root = Tk()
root.title("Hello example")
root.geometry("250x280")
w = Label(root, text="Good Bye")
b = Button(text="Hello world", width=20, height=2, command=mhello)
w.pack()
b.pack()
root.mainloop()
ผลรัน
เมื่อกดปุ่ม Hello world สามารถเรียกฟังก์ชันที่เราสร้างขึ้นมาได้ ดังภาพ
ศึกษาจาก: Exploring Python