-
-
Save JeffersGlass/ba12d6bc5fc2cfabec93e8b6d2f85ebf 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 | |
from sys import exit | |
class App(tk.Frame): | |
def __init__(self, master): | |
super().__init__(master) | |
self.basicFont = tkfont.Font(family='Lucida Grande', size=24) | |
self.makeLabels() | |
self.config(bg="#FFCCCC", width=300, height = 300) | |
self.pack(fill=tk.BOTH, expand=1) | |
def makeLabels(self): | |
#button | |
self.but = tk.Button(self, text="Button!", font=self.basicFont) | |
self.but.grid(row=0, column=0) | |
#checkbutton | |
self.checkVar = tk.IntVar() | |
self.check = tk.Checkbutton(self, text="Checkbox!", variable=self.checkVar, font=self.basicFont) | |
self.check.grid(row=1, column=0) | |
#Entry | |
self.eVar = tk.StringVar() | |
self.eVar.set("An entry!") | |
self.eVar.trace_add("write", self.textchange) | |
self.entry = tk.Entry(self, textvariable=self.eVar, font=self.basicFont) | |
self.entry.grid(row=2, column=0) | |
#Label | |
self.firstLabel = tk.Label(self, text="I'm a label!", font=self.basicFont, bg="#CCFFCC") | |
self.firstLabel.grid(row=3, column=0) | |
#Listbox | |
self.lb = tk.Listbox(self) | |
self.lb.insert(tk.END, "First") | |
self.lb.insert(tk.END, "Second", "Third") | |
myList = ["Fourth", "Fifth"] | |
self.lb.insert(tk.END, *myList) | |
self.lb.insert(0, "Zero") | |
self.lb.grid(row=4, column=0) | |
#TODO lb.curselection | |
#Menus | |
self.menubar = tk.Menu(self.master) | |
self.filemenu = tk.Menu(self.menubar, tearoff=0) | |
self.filemenu.add_command(label="New",command=None) | |
self.filemenu.add_separator() | |
self.filemenu.add_command(label="Quit", command=exit) | |
self.menubar.add_cascade(label="File", menu=self.filemenu) | |
self.master.config(menu=self.menubar) | |
#Message | |
self.mes = tk.Message(self, text="This is a message", width=300, font=self.basicFont) | |
self.mes.grid(row=5, column=0) | |
#Frames | |
rFrame = tk.Frame(self) | |
#Radiobuttons | |
rVar = tk.IntVar() | |
for i in range(1,4): | |
rBut = tk.Radiobutton(rFrame, text="Option" + str(i), variable=rVar, value=i, font=self.basicFont) | |
rBut.grid(row=0, column=i) | |
rFrame.grid(row=6, column=0) | |
#Scale | |
self.sVar = tk.DoubleVar() | |
self.scale = tk.Scale(self, from_=0, to=100, orient=tk.HORIZONTAL, variable=self.sVar) | |
self.scale.grid(row=0, column=1) | |
#Spinbox | |
self.sbVar = tk.StringVar() | |
self.sBox = tk.Spinbox(self,from_=0, to=59, wrap=True, textvariable=self.sbVar, width=5) | |
self.sBox.grid(row=1, column=1) | |
#OptionMenu | |
self.oVar = tk.StringVar() | |
self.om = tk.OptionMenu(self, self.oVar, *["Option "+str(i) for i in range(5)]) | |
self.om.grid(row=2, column=1) | |
def textchange(self, *args): | |
self.firstLabel['text'] = self.eVar.get() | |
self.mes['text'] = self.eVar.get() | |
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