Yes you can keep them separate by changing the class variables store_number & tld_date. To do this, you need to get the numbers from the entryboxes and save them as variables. We can conveniently do this by calling self.store_number = self.entStore.get() or self.tld_date = self.entDate.get()
MainUI.py
from tkinter import *
class LaunchMainUi:
store_number = ''
tld_date = ''
def __init__(self, root):
self.root = root
root.title("TacoBell TLD Tool")
self.store_number = IntVar()
self.tld_date = IntVar()
Label(root, text="Store Number (XXXXXX): ").grid(row=0, sticky=E) # Sticky align text North(N), East(E), South(S), West(W)
Label(root, text="TLD Date(MM/DD/YYYY): ").grid(row=1, sticky=E)
self.entStore = Entry(self.root)
self.entDate = Entry(self.root)
self.entStore.grid(row=0, column=1)
self.entDate.grid(row=1, column=1)
self.confirm = Button(root, text="Confirm", command=self.save)
self.confirm.grid(row=2, column=1)
def save(self, event=None):
storeNumber = self.entStore.get()
tldDate = self.entDate.get()
#Saved as method variables ^ in order to perform necessary validation checks easier
#If entered items are valid:
self.store_number = storeNumber
self.tld_date = tldDate
self.root.destroy()
I firstly changed the name of the class so that the file name and the class name do not clash. I then created a button called self.confirm and set it's command to self.save. This function stores the two variables as storeNumber and tldDate, before setting the class variables to what as been entered and destroying the root window.
Controller.py
import MainUI
from tkinter import *
root = Tk()
ui = MainUI.LaunchMainUi(root)
root.mainloop() #Keeps the ui instance running until closed, then the rest of the code is run
storeNum = ui.store_number
tldDate = ui.tld_date
print('Store Number: {}\nTLD Date: {}'.format(storeNum, tldDate)) #This line is to show that the variables can be accessed
Because we destroyed the root instance, the mainloop() function is returned meaning that any code underneath it will run. As long as the UI is open, the code under it won't be run. So when the root window is closed the code underneath it is run saving the two variables for later use. You should add some error-checking code where it is commented out to.
Using .pack()
I personally stay away from using .grid() because is can be a bit confusing. Instead I like to use .pack() and encapsulation.
If you'd want to use .pack() instead, here is another __init__ that works just the same. I also made the GUI look a little less standard on this __init__ and with some TacoBell colours :)
def __init__(self, root):
self.root = root
self.root.title("TacoBell TLD Tool")
self.root.geometry('600x300')
font20 = 'Calibri 20'
bfont20 = font20 + ' bold'
Label(self.root, text='TacoBell TLD Tool', font=bfont20, fg='purple').pack()
topItems = Frame(self.root)
Label(topItems, text="Store Number (XXXXXX): ", font=font20).pack(side=LEFT) # Sticky align text North(N), East(E), South(S), West(W)
self.entStore = Entry(topItems, font=font20)
self.entStore.pack(side=RIGHT)
topItems.pack(pady=20)
lowItems = Frame(self.root)
Label(lowItems, text="TLD Date(MM/DD/YYYY): ", font=font20).pack(side=LEFT)
self.entDate = Entry(lowItems, font=font20)
self.entDate.pack(side=RIGHT)
lowItems.pack(pady=20)
self.confirm = Button(root, text="Confirm", bg='purple', fg='white', font=bfont20, width=30, command=self.save)
self.confirm.pack()