Here we are providing basic tutorial in Tkinter required by a beginner python developer. This topic explains about a widget called as buttons.

Code

from tkinter import *

root=Tk()

theButton = Button(None, text="Click", fg="Blue")
theButton.pack()

root.mainloop()

First few lines of the code is explained in Introduction. In this code, we created a buttons theButton by using method Button, method is passed the fg parameter that is used to set the foreground of the button and text that must appear on the label. Also first parameter is None, it will be explained later in Organizing layout.

Output

output


Consider this sample code also


from tkinter import *

root=Tk()

theButton = Button(None, text="Click", fg="Blue")
theButton.pack()

theButtons = Button(None, text="Click me", fg="Red")
theButtons.pack()

root.mainloop()


Output

output