-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomboboxwidget.py
35 lines (25 loc) · 939 Bytes
/
comboboxwidget.py
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
32
33
import tkinter as tk
from tkinter import ttk
win=tk.Tk()
win.title("Working with combo boxes")
#adding a label
aLabel=ttk.Label(win,text="Combo boxes")
aLabel.grid(column=0,row=0)
def clickMe():
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 name from the 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="Clicke 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') #adding a readonly state to the combo box making it not write able
numberChosen['values']=(range(50))
numberChosen.grid(column=1,row=1)
numberChosen.current(0)
win.mainloop()