โดย Jom07 » 28/02/2018 6:36 pm
การใช้งาน Python GUI (Tkinter) : การ Combobox เป็นการสร้างหน้าต่างที่กำหนดตัวเลือกโดยเฉพาะ เช่น
ตัวอย่าง
โค้ด: เลือกทั้งหมด
from tkinter import *
from tkinter import ttk
def obtener():
if int(combo.get()) >15:
texto.set("Edad: " + combo.get() + ". E")
else:
texto.set("Edad: " + combo.get() + ". E")
ventana = Tk()
texto = StringVar()
texto.set("Edad : ")
combo = ttk.Combobox(ventana)
combo.place(x=50,y=100)
combo['values'] = ('15', '16', '17' ,'18','19','20')
combo.current(3)
boto = Button(ventana,command=obtener,text="Calcular").place(x=100,y=150)
etiqueta = Label(ventana,textvariable=texto).place(x=40,y=200)
ventana.geometry("300x300")
ventana.mainloop()
ผลรัน
การใช้งาน Python GUI (Tkinter) : การ Combobox เป็นการสร้างหน้าต่างที่กำหนดตัวเลือกโดยเฉพาะ เช่น
[b]ตัวอย่าง[/b]
[code]from tkinter import *
from tkinter import ttk
def obtener():
if int(combo.get()) >15:
texto.set("Edad: " + combo.get() + ". E")
else:
texto.set("Edad: " + combo.get() + ". E")
ventana = Tk()
texto = StringVar()
texto.set("Edad : ")
combo = ttk.Combobox(ventana)
combo.place(x=50,y=100)
combo['values'] = ('15', '16', '17' ,'18','19','20')
combo.current(3)
boto = Button(ventana,command=obtener,text="Calcular").place(x=100,y=150)
etiqueta = Label(ventana,textvariable=texto).place(x=40,y=200)
ventana.geometry("300x300")
ventana.mainloop()
[/code]
[b]ผลรัน[/b]
[img]http://snap.mindphp.com/index.php?view=2018Feb28_5a9690ff8656e[/img]