How to Create Status and hover in Python - learnit

Home Top Ad

Post Top Ad

Friday, April 9, 2021

How to Create Status and hover in Python

How to Create Status and hover in Python

How to Create Status and hover in Python

Why Learn Python?

Python is a general-purpose, versatile and popular programming language. It is great as a first language because it is concise and easy to read, and it is a good language to have in any programmer’s stack as it can be used for everything from web development to software development and scientific applications.


Take-Away Skills

This course is a great introduction to both fundamental programming concepts and the Python programming language. By the end, you will be comfortable programming in Python and taking your skills off the Codecademy platform and onto your own computer.


Button in Tkinter

In this tutorial, we are going to learn about the button widget in tkinter, we will be looking at how to display button on the screen as well as discuss the features and their properties in detail.

1)What is a Button in Tkinter?

2)Creating a Simple Button


What is a Button in Tkinter?

The button widget in Tkinter is used to add different types of buttons on the main window that you are working on. You can modify button settings to your own requirements. You can also add a function to the button and call whenever the button is pressed. You can create a button as follows

button_tk = Button(window, features)


Creating a Simple Button

ID Name Description
1 activebackground Shows the button background color upon the mouse hover
2 activeforeground Shows the button font color upon the mouse hover
3 Bd It shows the width of the border in pixels
4 Bg It shows the background color of the button
5 Command It is used to set the function call whenever it is called.
6 fg Shows the foreground color of the button
7 Wraplength This is used to wrap text lines within the given length
8 Width This feature sets the width of the button
9 Underline It is used to underline the text present on the button
10 State This represents DISABLED or ACTIVE state of the button
11 Relief This displays different types of borders like SUNKEN, RAISED, GROOVE, and RIDGE
12 pady This adds padding in vertical direction
13 Font It decides the font of the button text
14 Height It decides the height of the button.
15 Highlightcolor It shows the highlight color of the button when it is clicked
16 Image It is used to set image on the button
17 justify It is used to display text on button in RIGHT, LEFT and CENTER justified positions
18 Padx This adds padding in horizontal direction

Example

from tkinter import *
from tkinter import ttk
root=Tk()
root.title('www.reanits.com')
root.iconbitmap('1.png')
root.geometry("300x400")
def buttonhover(e):
    mybutton["bg"]="Yellow"
    statulabel.config(text="Knowledge Edcuation Cambodia")
def buttonleave(e):
    mybutton["bg"] = "SystemButtonFace"
    statulabel.config(text="")
mybutton= Button(root, text="Cambodia", font=("Preah Vihear",12))
mybutton.pack(pady=20)
statulabel= Label(root, text="welcome", bd=1, relief=SUNKEN, anchor=E)
statulabel.pack(fill=X, side=BOTTOM, ipady=2)
mybutton.bind("<Enter>", buttonhover)
mybutton.bind("<Leave>",buttonleave)
root.mainloop()


Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad