I have 2 python Files, FirstWindowFile
and SecondWindowFile
.
I create one button in 1st and I want, after pressing it, to create
a new window with a button in the 2nd file.
After pressing the button in the 2nd file, I need to change the
value of the global variable in 1st.
FirstWindowFile
code:
import tkinter as tk
from tkinter import*
import SecondWindowFile
root = Tk() # create a main window
root.geometry("750x250")
global myglobal # this is the global i want to change
myglobal = 0
btn1 = tk.Frame(root, borderwidth=5, relief="ridge")
btn1.grid(column=0, row=0)
# when I press this button I send the SecondWindowFile to ChangeValue()
Analyze = tk.Button(btn1, text="Analyze",
command=lambda: SecondWindowFile.ChangeValue()).grid(row=0, column=0)
# myglobal has to take new value (sent from SecondWindowFile) so to
# be used for new calculations
print(myglobal)
root.mainloop()
SecondWindowFile
code:
import tkinter as tk
from tkinter import*
def changeMyNum():
gl=1
# I need this value of gl to be returned to the FirstWindowFile and be the
# new value of global myglobal
def ChangeValue():
secondWindow = Tk() # create a 2nd window
secondWindow.geometry("150x150")
btn2 = tk.Frame(secondWindow, borderwidth=5, relief="ridge") # create a button
btn2.grid(column=0, row=0)
# by pressing the button goes to changeMyNum()
ChangeVal = tk.Button(secondWindow, text="Press to Change Global",
command=lambda: changeMyNum).grid(row=0, column=0)