I want to be able to change the background colour of a Tkinter frame in a thread, the frame is declared in a separate function. I receive the following error when I run the following code.
Error:
NameError: name 'mainScreen' is not defined
Code:
import tkinter as tk
from tkinter import ttk
from multiprocessing import Process
def main():
global mainScreen
root = tk.Tk()
root.geometry('1040x540+50+50')
mainScreen = tk.Frame(root, width = 1040, height = 540)
mainScreen.place(x=0, y=0)
root.mainloop()
def test(): # This function is in a thread as it will be run as a loop.
while True:
mainScreen.configure(bg='red')
if __name__ == '__main__':
p2 = Process(target = test)
p2.start()
main()
Any help is appreciated.