Skip to content

Instantly share code, notes, and snippets.

@ROBOMASTER-S1
Last active March 8, 2023 02:12
Show Gist options
  • Save ROBOMASTER-S1/aa8b230f8fab59412ca548e90bd67688 to your computer and use it in GitHub Desktop.
Save ROBOMASTER-S1/aa8b230f8fab59412ca548e90bd67688 to your computer and use it in GitHub Desktop.
Tkinter Button and Label Python Program Examples: Created by Joseph C. Richardson
# Let's create a button with tkinter and see what happens when
# you type and execute/run the tkinter program example below.
# Created by Joseph C. Richardson, GitHub.com
from tkinter import*
button=Tk()
button.geometry('500x500')
button_1=Button(button,text='Click Me!')
button_1.pack()
button.mainloop()
# Let's create a label for our tkinter button and see what happens
# when you type and execute/run the tkinter program example below.
from tkinter import*
button=Tk()
button.geometry('500x500')
label_1=Label(button,text=' "Python Programmer\'s Glossary Bible" ')
button_1=Button(button,text='Click Me!')
label_1.pack()
button_1.pack()
button.mainloop()
# Let's make the tkinter button call the label with a 'def' function.
# Every time the 'Click Me!' button is clicked, the 'def' function gets
# called and the label is displayed again. See what happens when
# you type and execute/run the tkinter program example below.
from tkinter import*
button=Tk()
def call_the_def_function():
label_1=Label(button,text=' "Python Programmer\'s Glossary Bible" ')
label_1.pack()
button.geometry('500x500')
button_1=Button(button,text='Click Me!',command=call_the_def_function)
button_1.pack()
button.mainloop()
# Let's reposition the tkinter button and its label by invoking the 'side=
# TOP' statement for the label and the 'side=LEFT' statement for the
# tkinter button. See what happens when you type and execute/run the
# tkinter program example below.
from tkinter import*
button=Tk()
def call_the_def_function():
label_1=Label(button,text=' "Python Programmer\'s Glossary Bible" ')
label_1.pack(side=TOP)
button.geometry('500x500')
button_1=Button(button,text='Click Me!',command=call_the_def_function)
button_1.pack(side=LEFT)
button.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment