I have been writing an annual data verification program and need a bit of user input with it and decided to go the tkinter route. I have created the interface for one of the user input screen, and will have to make others, but I'm having some issues with the destruction of the windows after a selection is made, and the globalization of the variable.
So ideally the program is run, the window pops up, an appropriate attribute selection is made, the text on that button is passed to the "assign" function, which creates a global variable to be used in my program, and the window disappears.
As it stands now, the running of this code results in an error: "TclError: can't invoke "button" command: application has been destroyed".
If I comment out the "mGui.destroy()" line, I can select a button and close the window manually, but the "DRN" variable is passed to variable "x" no matter what!
import sys
from Tkinter import *
def assign(value):
global x
x = value
mGui.destroy()
mGui = Tk()
mGui.geometry("500x100+500+300")
mGui.title("Attribute Selection Window")
mLabel = Label(mGui, text = "Please select one of the following attributes to assign to the selected Convwks feature:").pack()
mButton = Button(mGui, text = "CON", command = assign("CON")).pack()
mButton = Button(mGui, text = "MS", command = assign("MS")).pack()
mButton = Button(mGui, text = "DRN", command = assign("DRN")).pack()
mGui.mainloop() #FOR WINDOWS ONLY
Bonus problem: Putting all of the buttons on the same row with spaces in between them, while keeping them centered.