Python: Crear un GUI SIMPLE con Tkinter

Posted by

Primer PROGRAMA en Python con INTERFAZ

#shorts #python: Create a SIMPLE GUI using Python and Tkinter

Python is a powerful programming language that is commonly used for web development, data analysis, and automation. It also has the capability to create Graphical User Interfaces (GUI) using its built-in library called Tkinter.

In this article, we will create a simple program in Python with a GUI using Tkinter. This program will serve as your first step in learning how to create GUI applications in Python.

Setting Up the Environment

Before we start coding, make sure you have Python installed on your computer. You can download and install Python from the official website.

Creating the GUI

Now, let’s start by creating a simple GUI using Tkinter. Open your favorite text editor and create a new Python file. In this file, we will write the following code:

“`python
from tkinter import Tk, Label, Button

class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title(“My First GUI”)

self.label = Label(master, text=”This is our first GUI!”)
self.label.pack()

self.greet_button = Button(master, text=”Greet”, command=self.greet)
self.greet_button.pack()

self.close_button = Button(master, text=”Close”, command=master.quit)
self.close_button.pack()

def greet(self):
print(“Hello!”)

root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()
“`

Save the file as “first_gui.py” and run it using the Python interpreter. You should see a window pop up with a label and two buttons. Clicking the “Greet” button should print “Hello!” in the console, and clicking the “Close” button should close the window.

Conclusion

Congratulations! You have just created your first program in Python with a GUI using Tkinter. This is just the beginning of your journey in creating more complex and functional GUI applications using Python. Keep on learning and exploring the capabilities of Tkinter and other GUI libraries to enhance your programming skills.

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Byspel
6 months ago

Curso completo de Python con Interfaz gráfica

https://youtube.com/playlist?list=PLAlpGdBI2ecfDFtZCRbJGGNkLHKtHQLqq