I have created a program that gets selection from the drop-down menu in Tkinter. When I run it from the same file the drop-down widget shows what I have selected.
But when I try running it from a different file by importing the function, the selection is not displayed. I am able to select options from the drop-down but what i select is not showing up.
This is my code in the main file(test2.py) where the drop-down menu is created:
import mysql.connector as sql
from tkinter import *
import re
def servicingwindow1():
root2=Tk()
root2.title("SERVICING")
root2.geometry("320x300")
root2.configure(bg='#ffa366')
selcom=StringVar()
selmod=StringVar()
companies=["com1","com2"]
cars=["car1","car2"]
model_box=OptionMenu(root2,selmod,*cars)
model_box.grid(row=3,column=1)
name=Label(root2,text="Your Name")
name.grid(row=0,column=0,padx=8,pady=(5,0))
company=Label(root2,text="Car Company")
company.grid(row=1,column=0)
model=Label(root2,text="Car Model")
model.grid(row=3,column=0)
licenseno=Label(root2,text="Licenseno")
licenseno.grid(row=4,column=0)
name_box=Entry(root2,width=35,borderwidth=2)
name_box.grid(row=0,column=1,pady=(5,0))
company_box=OptionMenu(root2,selcom,*companies)
company_box.grid(row=1,column=1)
licenseno_box=Entry(root2,width=35,borderwidth=2)
licenseno_box.grid(row=4,column=1)
submitbtn=Button(root2,text="SEND FOR SERVICE")
submitbtn.grid(row=5,column=0,columnspan=2,padx=10,pady=5,ipadx=50)
root2.mainloop()
This is the code in my other file(test1.py) where I imported the function from the main file:
from tkinter import *
from test2 import servicingwindow1
root=Tk()
root.title("LOGIN")
root.geometry("300x200")
root.configure(bg='#66d9ff')
password=Label(root,text="PASS")
password.grid(row=2,column=0)
pass_box=Entry(root,width=35,borderwidth=2)
pass_box.grid(row=2,column=1)
p="test"
def submitpass():
if pass_box.get()==p:
passshow=Label(root,text="CORRECT OTP")
passshow.grid(row=4,column=0,columnspan=2,padx=8,pady=(5,0))
servicingwindow1()
else:
passshow=Label(root,text="INCORRECT OTP")
passshow.grid(row=4,column=0,columnspan=2,padx=8,pady=(5,0))
checkbtn=Button(root,text="CHECK OTP",command=submitpass)
checkbtn.grid(row=3,column=0,columnspan=2,padx=10,pady=5,ipadx=50)
root.mainloop()
How do I display the selection when running from the other file?