Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)--hello world!

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/hhh5460/p/4232086.html

Preface

I am a rookie, this series is my study notes.

PyQt5 out for some time, PyQt5 compared to PyQt4 some changes, and the Internet is almost all the PyQt4 of the tutorial, copy the words will be wrong most.

ERIC6 is also just out, eric6 and PyQt5 combine the tutorials online with almost no.

I am also learning, while groping, and record with this, hope to help the needs of friends, but also hope to pass the hero more advice as well.

Introduction

With the combination of eric6 and PyQt5, it is very convenient to implement interface and logic separation, to meet Python's fast GUI programming, you just need to focus on the logic implementation of the program, do not need to spend a lot of time on the interface.

It can be said that this is a perfect combination!

The following content is based on: Windows 7 + python 3.4.2 + PyQt5 + Eric 6

Overview

This article implements the following program:

The main steps are as follows:

1. Create a new project in ERIC6

2. Enter PYQT5 Desinger Edit graphical interface (automatic entry), and save

3. Back to Eric 6 to compile the interface file just now

4. Then add your own program logic to the interface

5, Py2exe package into EXE file (this step)

Body

1. Create a new project in ERIC6

2. Enter PYQT5 Desinger Edit graphical interface (automatic entry), and save

Add a text label (label), two buttons (pushbutton) to a form

Set the text label, the object name of the two buttons (objectName) to: Label_hello,pushbutton_ok,pushbutton_close

Set text label, two-button text (text) as: "Show Here", "OK", "Exit"

Add a signal/slot to the exit button (Note: The signal/slot mechanism is the PYQT unique signal transfer mechanism, very convenient to use)

Save, and then close PYQT Designer

3. Back to Eric 6, compile the interface file just now

After returning to Eric 6, I found a hello.ui file under the form, which is essentially an XML format file that cannot be run and needs to be right-clicked.

After the successful compilation, found that the source files are more than the ui_hello.py file, this file can be run

Try to run it,

wow! The interface came out. Everything is fine. But you will find that only the Exit button works, and the OK button does not respond. That's because we haven't added the logic code to the OK button.

It's a good thing to do. Right-click the Hello.ui file in the form to select the Generate dialog box code

Check here for on_pushbutton_ok_clicked () under Pushbutton

Back to the source code, found another hello.py file

No matter 3,721, run it first. Yes! Error!!!

This error should be a bug in Eric 6!!!, remove the dot in front of the UI, then run, there is no error. Oh, that's great! Eh, wait a minute, why didn't you see the form coming out?

A few lines of code are missing, which can be considered a bug in Eric 6. Do it yourself, add these lines at the bottom of the hello.py:

 1  if  _ _name__  = =  " __main__  "  :  2  import   sys  3  from  pyqt5.qtwidgets import   qapplication  4  app = Qapplication ( SYS.ARGV)  5  dlg = Hello ()  6   Dlg.show ()  7  sy S.exit (App.exec_ ()) 

Long hush breath, the form finally came out again, but click OK button when the error is also. The reason is simple, we haven't addressed the logic code to determine the button

Delete the original code and change it to a sentence. Yes, our logic code is a code:

Self.label_hello.setText ('Hello world! ')

Save it and run it. OK, you are done!

Finally, Eric + PyQt is really handy for Python GUI programming, just focus on the logic implementation.

Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)--hello world!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.