-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTkinter Optionmenu [full].py
More file actions
38 lines (27 loc) · 975 Bytes
/
Tkinter Optionmenu [full].py
File metadata and controls
38 lines (27 loc) · 975 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
32
33
34
35
36
37
38
# ;==========================================
# ; Title: Tkinter Optionmenu [full]
# ; Author: @AyemunHossain
# ;==========================================
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
frame1 = tk.Frame(root)
frame1.pack(expand=tk.TRUE)
country_v= tk.StringVar()
country_v.set("Select One")
f = open("all_country.txt",'r')
data = f.read()
linedata= data.split('\n')
country_list = []
for line in linedata:
country_list.append(line)
f.close()
label1 = tk.Label(frame1,text="Select Your Country: ",bg="#ada4a3")
label1.pack(side=tk.TOP)
country = tk.OptionMenu(frame1, country_v, *country_list)
country.pack()
button2 = tk.Button(frame1,text="My Country",width=10,bg='brown',fg='white',
command=lambda :[messagebox.showerror("Select First") if str(country_v.get()) == "Select One"
else print(f"Your Country is {country_v.get()}")])
button2.pack()
root.mainloop()