-
-
Save JeffersGlass/7307b47a46350f4b71a61f1ba35a1bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from functools import partial | |
import tkinter.font as tkfont | |
class App(tk.Frame): | |
def __init__(self, master): | |
super().__init__(master) | |
self.basicFont = tkfont.Font(family='Lucida Grande', size=30) | |
self.makeLabels() | |
self.config(bg="#FFCCCC", width=300, height = 300) | |
self.pack(fill=tk.BOTH, expand=1) | |
def makeLabels(self): | |
self.firstLabel = tk.Label(self, text="I'm a variable label!", font=self.basicFont, bg="#CCFFCC") | |
self.firstLabel.pack(fill=tk.X, expand=1) | |
for i in range(5): | |
but = tk.Button(self, text=str(i), font=self.basicFont, command=partial(self.numBut, i)) | |
but.pack() | |
def clickedTheBut(self): | |
print("You clicked the button!") | |
def numBut(self, number): | |
print(f"You cliked the button numbered {number}") | |
self.firstLabel['text'] = "You clicked the number " + str(number) | |
if __name__ == '__main__': | |
myApp = App(tk.Tk()) | |
myApp.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment