This is my first question so be gentle!
Situation: I have two scripts that each use tkinter to prompt for some info. They are separate because sometimes I'll need one, sometime I'll need both.
I also have a main script that imports the two tkinter scripts and calls them.
When I run each tkinter by itself, or from the main script without the other script imported, it works fine. When I import both scripts, a blank tkinter (title = "tk") window pops up.
Questions: 1. What is causing this? 2. How can I prevent that stupid window from popping up? 3. Is there an automated way to see that extra window and kill it when it does show?
What I've done:
- Googled my hiney off
- Renamed Tk import so each script has its own instance
- Banged my head on the desk
Code: uidpassform (first script that directly uses tkinter)
from tkinter import Tk as lf2Tk
from tkinter import Label, StringVar, Entry, Button
o_window = lf2Tk()
username = StringVar()
password = StringVar()
def close_dialog():
o_window.destroy()
def uidpass form():
#Return the value of the selected option
o_window.title('Oracle Login Credentials')
#username label and text entry box
Label(o_window, text="User Name").grid(row=2, column=0,padx = 5,pady = 20)
Entry(o_window, textvariable=username).grid(row=2, column=2, padx=20)
#password label and password entry box
Label(o_window,text="Password").grid(row=3, column=0,padx = 5)
Entry(o_window, textvariable=password, show='*').grid(row=3, column=2,padx = 20)
#login button
Button(o_window, text="Connect", command=close_dialog).grid(row=4, column=3,columnspan=2, padx = 20)
Label(o_window, text="").grid(row=5)
o_window.mainloop()
print (username.get())
print (password.get())
return [username.get(), password.get()]
if __name__ == "__main__":
uidpassform()
radiobutton form (second tkinter form)
from tkinter import Tk as rbTK
from tkinter import Radiobutton, Button, Label, IntVar, LEFT, W
rb_window = rbTK()
v = IntVar()
def validate():
#Display the value of the selected option for debugging purposes
value = v.get()
return (value)
def close_dialog():
#Check to see if the Radiobutton has a value and if so, close the form
value = v.get()
if value == 0:
value = v.get()
else:
rb_window.destroy()
def fnradiobutton():
#Return the value of the selected option
rb_window.title("Connection")
Label(rb_window, text="Choose a Data Connection:", justify=LEFT, padx=20).grid(row=0, sticky=W)
Radiobutton(rb_window, text="Production", variable=v, value=1, command=validate).grid(row=1, padx=20, sticky=W)
Radiobutton(rb_window, text="Test", variable=v, value=2, command=validate).grid(row=2, padx=20, sticky=W)
Button(rb_window, text="Done", command=close_dialog).grid(row=3, column=2, padx=10)
Label(rb_window, text="").grid(row=4)
#print(str(V.get()) + " from fnradiobutton")
rb_window.mainloop()
return v.get()
if __name__ == "__main__":
fnradiobutton()
Main script (calls the two tkinter scripts)
import cx_Oracle
import lf2 as lf
import time
import radiobutton as rb
import pyodbc
def oracle_connection():
#Get Oracle UserID and password
uidpass_list = lf.uidpassform()
#Create the connection
try:
oracle_conn = cx_Oracle.connect(uidpass_list[0], uidpass_list[1], 'robanner', encoding='UTF-8')
except:
return oracle_conn
def dbconnect(switch):
#Choose the proper connection, based on the radiobutton form
if switch == 1:
connection = pyodbc.connect('DSN=PCard_Production;Trusted_Connection=yes;')
else:
connection = pyodbc.connect('DSN=PCardTest;Trusted_Connection=yes;')
return connection
def run_script():
start = time.time()
oracle_conn = oracle_connection()
swich = rb.fnradiobutton()
conn = dbconnect(swich)
if __name__ =='__main__':
# This is the summary spot
run_script()