Using Buttons in Python - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Saturday, December 10, 2022

Using Buttons in Python

 Hello friends, in this article, we will look at how to add a button to our form in Python tkinter.

Before we can add a button to our form,


import tkinter as tk

 

we need to add this expression to our form. Then we add the properties of the button in the tk.Button section.

In this part, by typing exit in the command section, we will exit the form when the button is clicked.

We determine the text color of the button with the fg feature, and the background color with the bg feature. In the Text section, we can specify the text that will appear on the button. With padx and pady, we determine the coordinates where the button will be located in the form.

 


 

 

 

 

 

 

 

Figure 1

 

Pyton_form_button.py

 

import tkinter as tk

from tkinter import *

 

form = Tk()

 

form.title("python example...bs")

form.geometry("500x250")

 

process = Frame(form)

process.grid()

 

#here I am changing the button style. 

 

btnExit = tk.Button(process, text = " Exit " , width=30,height=3, command=exit,font='arial 14 bold', fg='white', bg='deepskyblue')

btnExit.pack()

btnExit.grid(padx=50, pady=80)

 

form.mainloop()

 

We have come to the end of this article. See you in our next article. Happy coding. Bahadir Sahin

No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...