Jun-30-2018, 04:52 AM
I am trying to make a GUI to have choices on what action to do to fill another window. I can get the window to work with hard-coded options (and a different file for each option choice), but would prefer to use a GUI (without having it be a selector for which specialized python file to run) to select the options.
Here is a simplified example (I add .01 to the value because for the full thing I would like to do a variety of functions with the numerical values and modify the text to similar strings and then use that as an option selection, both of which work fully, when hardcoded).
Here is a simplified example (I add .01 to the value because for the full thing I would like to do a variety of functions with the numerical values and modify the text to similar strings and then use that as an option selection, both of which work fully, when hardcoded).
from tkinter import * root = Tk() root.lift() root.title('Test') root.geometry('500x100') Number = Label(root) Number.pack() numeral = StringVar() Number['textvariable'] = numeral numeral.set('Nothing has been entered into the GUI') GUI = Tk() GUI.lift() GUI.title('GUI') GUI.geometry('300x100') num = StringVar() numBox = Entry(GUI, textvariable=num) numBox.pack() def Load(): while 1: try: Fill = (int(num.get()) + .01) except Exception: try: Fill = (int(str(num.get())) + .01) except Exception: try: Fill = str('{}?'.format(num.get())) except Exception: pass try: numeral.set('{} is entered into the GUI'.format(Fill)) except Exception: numeral.set('Nothing has been entered into the GUI') root.update() root.after(100, Load) root.mainloop()Currently, I am hard-coding it by using .set for the hard-coded value desired immediately following the initial occurrence of the tkinter variable. I have tried making the main window into a function with the value in the label a parameter of the function, and the GUI to have a button to close it and call the function to make the other window, but it also only works if the values are hard-coded. I have tried putting each variable through a middle-man global (or make the tkinter variable global and then have a local middle-man variable). I used the simplest code that I do not understand the flaw with in the example.