Tkinter GUI window and Label in Python

Hello friends how are you, today in this blog i will teach you what is Tkinter, how to create GUI window , how Tkinter GUI works and many programs using Tkinter in a very simple way.

Let's start

Python tkinter

  • Tkinter is GUI library for Python.
  • It is used to create graphical user interface for desktop application.
  • import the tkinter module in python program.
  • Create the GUI main window.
  • Add the widgets like labels, buttons etc. to the GUI window.
  • Call the main loop so that the actions can take place on the user's computer screen.

#importing tkinter
import tkinter
#creating object
top = tkinter.Tk()
# Code to add widgets will go here...
#calling mainloop
top.mainloop()
 





import tkinter
top = tkinter.Tk()
#setting dimension of window
top.geometry("325x200")
top.mainloop()

import tkinter
top = tkinter.Tk()
#setting dimension of window
top.geometry("325x200")
#setting title of window
top.title("Easy")
#setting background color
top['bg']="#51E1DC"
top.mainloop()
Output

Label

  • The Label widget is used to provide a caption for other widgets.
  • It can be used as a heading.
  • It can also contain images.
  • Syntax:
    lbl = Label ( master, option1,option2, ... )
    
  • Here master is parent window and option can be used as a key-value pairs.
  • Examples of options are text,bg,image,height etc.

from tkinter import *
top = Tk()
#window dimension
top.geometry("300x250")
top['bg']="#51E1DC"
# creating label
uname = Label(top, text="This is a label").place(x=30, y=50)
top.mainloop()
 
  • Here x is distance from left and y is distance from top.



Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks.😊

Post a Comment

0 Comments