โดย Jom07 » 08/02/2018 5:44 pm
การใช้งาน Python GUI (Tkinter) :Radio Buttons (ปุ่มเรดิโอ) เป็นการสร้างปุ่มตัวเลือกแบบเรดิโอ
ตัวอย่าง
โค้ด: เลือกทั้งหมด
import tkinter as tk
root = tk.Tk()
v = tk.IntVar()
tk.Label(root,
text="""Choose a programming language :""",
justify = tk.LEFT,
padx = 20).pack()
tk.Radiobutton(root,
text="Python",
padx = 20,
variable=v,
value=1).pack(anchor=tk.W)
tk.Radiobutton(root,
text="Perl",
padx = 20,
variable=v,
value=2).pack(anchor=tk.W)
tk.Radiobutton(root,
text="Java",
padx = 20,
variable=v,
value=3).pack(anchor=tk.W)
tk.Radiobutton(root,
text="C++",
padx = 20,
variable=v,
value=4).pack(anchor=tk.W)
tk.Radiobutton(root,
text="C",
padx = 20,
variable=v,
value=5).pack(anchor=tk.W)
root.mainloop()
ผลรัน
ศึกษาจาก :
https://www.python-course.eu/tkinter_radiobuttons.php
การใช้งาน Python GUI (Tkinter) :Radio Buttons (ปุ่มเรดิโอ) เป็นการสร้างปุ่มตัวเลือกแบบเรดิโอ
[b]ตัวอย่าง[/b]
[code]import tkinter as tk
root = tk.Tk()
v = tk.IntVar()
tk.Label(root,
text="""Choose a programming language :""",
justify = tk.LEFT,
padx = 20).pack()
tk.Radiobutton(root,
text="Python",
padx = 20,
variable=v,
value=1).pack(anchor=tk.W)
tk.Radiobutton(root,
text="Perl",
padx = 20,
variable=v,
value=2).pack(anchor=tk.W)
tk.Radiobutton(root,
text="Java",
padx = 20,
variable=v,
value=3).pack(anchor=tk.W)
tk.Radiobutton(root,
text="C++",
padx = 20,
variable=v,
value=4).pack(anchor=tk.W)
tk.Radiobutton(root,
text="C",
padx = 20,
variable=v,
value=5).pack(anchor=tk.W)
root.mainloop()
[/code]
[b]ผลรัน[/b]
[img]http://snap.mindphp.com/index.php?view=2018Feb08_5a7c26e9e6326[/img]
ศึกษาจาก : https://www.python-course.eu/tkinter_radiobuttons.php