[참고]


#======================

# imports

#======================

import tkinter as tk

from tkinter import ttk


# Create instance

win = tk.Tk()   


# Add a title       

win.title("Python GUI")  


# Modify adding a Label

a_label = ttk.Label(win, text="A Label")

a_label.grid(column=0, row=0)


# Modified Button Click Function

def click_me(): 

    action.configure(text='Hello ' + name.get())

#     print(number)

#     print(number.get())


# Changing our Label

ttk.Label(win, text="Enter a name:").grid(column=0, row=0)


# Adding a Textbox Entry widget

name = tk.StringVar()

name_entered = ttk.Entry(win, width=12, textvariable=name)

name_entered.grid(column=0, row=1)                          # column 0


# Adding a Button

action = ttk.Button(win, text="Click Me!", command=click_me)   

action.grid(column=2, row=1)                                # <= change column to 2


ttk.Label(win, text="Choose a number:").grid(column=1, row=0)

number = tk.StringVar()

number_chosen = ttk.Combobox(win, width=12, textvariable=number)

number_chosen['values'] = (1, 2, 4, 42, 100)

number_chosen.grid(column=1, row=1)                         # <= Combobox in column 1

number_chosen.current(0)


name_entered.focus()      # Place cursor into name Entry

#======================

# Start GUI

#======================

win.mainloop()



[결과]

(가운데 숫자1 있는 박스가 콤보 박스)



+ Recent posts