mirror of
https://github.com/Xevion/tkinter-mini-projects.git
synced 2025-12-05 23:16:36 -06:00
38 lines
761 B
Python
38 lines
761 B
Python
from tkinter import *
|
|
|
|
x = 1
|
|
y = 1
|
|
z = 0
|
|
|
|
class App:
|
|
def __init__(self, master):
|
|
frame = Frame(master)
|
|
frame.pack()
|
|
|
|
self.textVar = StringVar()
|
|
|
|
# Lambda Version
|
|
# self.button = Button(
|
|
# frame, textvariable=self.textVar, command=lambda: self.textVar.set(fibonacci())
|
|
# )
|
|
# self.button.pack()
|
|
|
|
# tkinter Version, using separate functions
|
|
self.button = Button(
|
|
frame, textvariable=self.textVar, command=self.update
|
|
)
|
|
self.button.pack()
|
|
|
|
def update(self):
|
|
self.textVar.set(str(fibonacci()))
|
|
|
|
def fibonacci():
|
|
global x, y, z
|
|
z = x
|
|
x = x + y
|
|
y = z
|
|
return x
|
|
|
|
root = Tk()
|
|
app = App(root)
|
|
root.mainloop() |