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

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

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

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

โดย Jom07 » 07/02/2018 4:32 pm

ทดสอบโดยโจย์จากหนังสือ 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

ข้างบน