728x90
#=======================================
# imports
#=======================================
import tkinter as tk
from tkinter import ttk
# Create instance
win = tk.Tk()
# Add a title
win.title("Python GUI")
# Adding a Label
a_label = ttk.Label(win, text="A label")
a_label.grid(column =0, row =0)
# Button Click Event Function
def click_me():
action.configure(text ="hello "+ name.get()+ " " + number_chosen.get())
# Change our Label
ttk.Label(win, text ="Enter a name :").grid(column =0, row =0)
# Adding a text box Entry widget
name = tk.StringVar()
name_entered = ttk.Entry(win, width =12, textvariable= name)
name_entered.grid(column =0, row =1)
# Adding a button
action = ttk.Button(win, text = "Click me!", command = click_me)
action.grid(column =2, row =1)
ttk.Label(win, text ="choose a number: ").grid(column =1, row=0)
number = tk.StringVar()
number_chosen = ttk.Combobox(win, width =12, textvariable = number, state ="readonly")
number_chosen['value'] =(1,2,4,42,100)
number_chosen.grid(column =1, row =1)
number_chosen.current(0)
name_entered.focus()
#=======================================
# Start GUI
#=======================================
win.mainloop()
728x90
'개발자 모드 > 파이썬(python)' 카테고리의 다른 글
파이썬 tkinter 라디오버튼 위젯 (0) | 2022.08.04 |
---|---|
파이썬 tkinter 체크박스 예제소스 (0) | 2022.08.04 |
파이썬 버튼 disable 시키기 (0) | 2022.08.01 |
파이썬 위젯에 포커스 설정하는 법 (0) | 2022.08.01 |
파이썬 버튼 예제 (0) | 2022.08.01 |