Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created November 9, 2020 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/7307b47a46350f4b71a61f1ba35a1bcf to your computer and use it in GitHub Desktop.
Save JeffersGlass/7307b47a46350f4b71a61f1ba35a1bcf to your computer and use it in GitHub Desktop.
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