PyQt- Klik Acara | PyQt- Tutorial Perekabentuk-3 | Tutorial Perekabentuk PyQt dalam Bahasa Melayu

Posted by


PyQt is a set of Python bindings for the Qt application framework and runs on all platforms supported by Qt including Windows, macOS, Linux, and more. It allows you to create desktop applications with a native look and feel using the Qt framework. In this tutorial, we will focus on click events in PyQt and how to handle them using PyQt Designer.

  1. Setting up PyQt and PyQt Designer:

Before we begin, make sure you have PyQt installed on your system. You can install PyQt using the following command:

pip install PyQt5

Once you have PyQt installed, you can open PyQt Designer by running the following command in your terminal:

designer

This will open up the PyQt Designer interface where you can design your GUI applications.

  1. Creating a simple GUI application in PyQt Designer:

In this tutorial, we will create a simple GUI application with a button that will change the text on a label when clicked.

Open up PyQt Designer and drag a push button and a label widget onto the form. Resize and position them as desired.

  1. Adding click event to the button:

To add a click event to the button, double click on the button widget to open the Edit Signal/Slot dialog. In the Signal section, choose clicked() and in the Slot section, choose on_button_clicked(). Click OK to confirm.

  1. Writing the code to handle the click event:

Now, we need to write the code to handle the click event. Click on the Edit menu and choose "Edit Widgets" to open the Signals/Slots editor.

In the tab for the button widget, double click on the clicked() event to open up the code editor. In the method on_button_clicked(self), write the following code:

def on_button_clicked(self):
    self.label.setText("Button Clicked!")

This code will change the text of the label widget to "Button Clicked!" when the button is clicked.

  1. Running the application:

Save your changes and generate the Python code for your PyQt application by clicking on the "File" menu and choosing "Save As Python Script". Save the file with a .py extension.

To run your application, simply open a terminal window and run the following command:

python your_script_name.py

Your PyQt application will open up, and when you click on the button, the text on the label widget will change to "Button Clicked!".

In this tutorial, we have covered how to handle click events in PyQt using PyQt Designer. With this knowledge, you can create interactive GUI applications using PyQt with ease. Experiment with different widgets and signals to create more complex applications. Happy coding!

0 0 votes
Article Rating

Leave a Reply

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@abhinavkoolath
2 hours ago

Bro oru help venam

1
0
Would love your thoughts, please comment.x
()
x