I have problem with returning a variable from custom pop-up, when the pop-up is in different .py file. As already answered on Stack Overflow, this can be solved with global variables. However this solution works only if all functions are in a single .py. Code representing the issue is following:
main.py:
from tkinter import *
import main_popups as main_popups
def main_screen():
global screen
screen = Tk()
main_btn= Button(screen, text = "Press me")
main_btn.pack()
main_btn.configure(command = pressed)
screen.mainloop()
def pressed():
main_popups.input_box(screen)
print(output_variable)
main_screen()
main_popups.py:
def input_box(screen):
global input_box_screen
def btn_press():
global output_variable
output_variable = entry.get()
input_box_screen.destroy()
input_box_screen.update()
print(output_variable)
input_box_screen = Toplevel(screen)
entry = Entry(input_box_screen)
entry.pack()
btn = Button (input_box_screen, text = "Confirm")
btn.pack()
btn.configure(command = btn_press)
screen.wait_window(input_box_screen)
This raises error at print(output_variable), as output_variable is not returned from btn_press in main_popups.py. My question is how to return the text from Entry in main_popups.py to main.py? I tried to return(output_variable) at the end of def btn_press():, but that does not return anything.