- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateComboboxWidget.py
More file actions
Latest commit
31 lines (23 loc) · 821 Bytes
/
Copy pathCreateComboboxWidget.py
File metadata and controls
31 lines (23 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
importtkinterastk
fromtkinterimportttk
win=tk.Tk()
win.title('Creating a Combobox')
defclickMe():
action.configure(text='Hello '+name.get() +' '+numberChosen.get())
# changing the label
ttk.Label(win, text='Enter a name:').grid(column=0,row=0)
# Adding a textbox Entry widget
name=tk.StringVar()
nameEntered=ttk.Entry(win, width=12, textvariable=name)
nameEntered.grid(column=0,row=1)
# Adding a button
action=ttk.Button(win, text='Click Me!', command=clickMe)
action.grid(column=2,row=1)
ttk.Label(win, text='Choose a number:').grid(column=1,row=0)
number=tk.StringVar()
numberChosen=ttk.Combobox(win, width=12, textvariable=number, state='readonly')
numberChosen['values'] = (1,2,4,42,100)
numberChosen.grid(column=1,row=1)
numberChosen.current(0)
nameEntered.focus()
win.mainloop()