การใช้งาน Python GUI (Tkinter) : Test options argument button (ปุ่มอาร์กิวเมนต์ตัวเลือกการทดสอบ)

แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Jom07
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 514
ลงทะเบียนเมื่อ: 08/01/2018 9:56 am

การใช้งาน Python GUI (Tkinter) : Test options argument button (ปุ่มอาร์กิวเมนต์ตัวเลือกการทดสอบ)

โพสต์ที่ยังไม่ได้อ่าน โดย Jom07 »

ทดสอบโดยโจย์จากหนังสือ 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
รูปภาพ
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 81