Выдает ошибку:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\User\Documents\Python\1.py", line 72, in one
if a==12345:
UnboundLocalError: local variable 'a' referenced before assignment
import tkinter as tk
global a
global b
a=12345
b=12345
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = '1'
self.hi_there["command"] = self.one
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '2'
self.hi_there["command"] = self.two
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '3'
self.hi_there["command"] = self.three
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '4'
self.hi_there["command"] = self.four
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '5'
self.hi_there["command"] = self.five
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '6'
self.hi_there["command"] = self.six
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '7'
self.hi_there["command"] = self.seven
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '8'
self.hi_there["command"] = self.eight
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '9'
self.hi_there["command"] = self.nine
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '0'
self.hi_there["command"] = self.null
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '+'
self.hi_there["command"] = self.add
self.hi_there.pack(side="top")
self.hi_there = tk.Button(self)
self.hi_there["text"] = '-'
self.hi_there["command"] = self.subs
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="STOP", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def one(self):
print("1")
if a==12345:
a=1
else:
b=1
def two(self):
print("2")
if a==12345:
a=2
else:
b=2
def three(self):
print("3")
if a==12345:
a=3
else:
b=3
def four(self):
print("4")
if a==12345:
a=4
else:
b=4
def five(self):
print("5")
if a==12345:
a=5
else:
b=5
def six(self):
print("6")
if a==12345:
a=6
else:
b=6
def seven(self):
print("7")
if a==12345:
a=7
else:
b=7
def eight(self):
print("8")
if a==12345:
a=8
else:
b=8
def nine(self):
print("9")
if a==12345:
a=9
else:
b=9
def null(self):
print("0")
if a==12345:
a=0
else:
b=0
def add(self):
print("+")
print("RESULT:", int(a)+int(b))
def subs(self):
print("-")
print("RESULT:", int(a)-int(b))
root = tk.Tk()
app = Application(master=root)
app.mainloop()