Setting options
#At object creation time, using keyword arguments
fred = Button(self, fg="red", bg="blue")
#After object creation, treating the option name like a dictionary index
fred["fg"] = "red"
fred["bg"] = "blue"
#Use the config() method to update multiple attrs subsequent to object creation
fred.config(fg="red", bg="blue")
#import tkinter
from tkinter import *
window = Tk()
window.title("My first GUI Program")
window.minsize(width=500, height=300)
#Label
my_labal = Label(text="I Am a Label", font=("Arial", "24", "bold"))
my_labal.pack()
my_label["text"] = "New text"
my_label.config(text = "New text")
#Button
def button_clicked():
print("I got clicked")
new_text = input.get()
my_label.config(text=new_text)
button = Button(text="Click me", command=button_clicked)
button.pack()
#Entry
def input_filled():
my_label.config(text=input.get())
input = Entry(width=10)
input.pack()
window.mainloop()
- So in the tkinter world, there is a property called command, which you can set to equal the name of a function. So remember, it's the name of the function, not calling the function. So we don't actually need the parentheses at the end.