How Python writes a graphical interface using the Aardio implementation

Source: Internet
Author: User
This article is mainly for you to introduce the use of Aardio python to write a graphical interface method, with a certain reference value, interested in small partners can refer to

The former is writing some small programs in Python, and then began to think about how to give the Python program a graphical interface, after all, the console is too ugly.

So Baidu the next Python Graphics interface Library, dazzling a full page, picked a few "features" have "gimmick" download down to do a demo, is still not very satisfied, not download installation cumbersome, is ugly or difficult to write the interface, the document is not complete.

Later that day, finishing computer files found 6 years ago downloaded Aatuo (now renamed Aardio), a sudden surprise.

First of all, aardio,2011 years July, it is also called Aauto, then the self is also obsessed with the development of desktop applications, VC + + (MFC), C # (Winform), Java (Swing), Delphi have been playing all over, occasionally online Baidu to the Aauto, Download it down and try it out, you will be moved by its IDE "no install" and "friendly", and the final release of EXE file is also very small, really is a very suitable for the development of small tools or small application language. Later, Aauto changed its name to Aardio, and I was fortunate to be a developer who witnessed Aardio's growth.

At the time, my first instinct was that Aardio should be able to write a graphical interface to Python, with the idea of trying it out, and I first wrote a simple function in Python that couldn't be simpler.


def add (A, B): Return a+b

Then, in the same way that I used to write a DLL in C, and then make other language calls, I followed the code example in Aardio and wrote this code:


Import Py3; var code = string.load ("add.py");p y3.exec (code);p y3.exec (code); __main__ = Py3.addmodule ("__main__"); Creating a Module Object

Edit the Click event for the Calculate button


Winform.button.oncommand = function (id,event) {//winform.msgbox (winform.button.text); var n1=tonumber ( Winform.n1.text); var n2=tonumber (Winform.n2.text); var s = tonumber (__main__.add (N1,N2)); Winform.sum.text=s;}

Final effect

In the end, I want to talk about Python, the scripting language, and we know that Python is an interpreted language, so you can run without compiling it. So for this aardio interface with the Python program, if you want to modify some functions later, only need to modify the py file with a text editor to run, without recompiling.

Code Listing:


Import win.ui;import Py3;/*dsg{{*/var WinForm = Win.form (text= "addition Calculator"; right=256;bottom=331) Winform.add (button={cls= "button"; text= "calculation"; left=72;top=267;right=188;bottom=305;z=1};equal={cls= "static"; left=30;top=156;right=237; bottom=181;transparent=1;z=6};n1={cls= "edit"; Left=72;top=30;right=188;bottom=68;edge=1;font=logfont (h=-29); multiline=1;z=3};n2={cls= "edit"; Left=72;top=92;right=188;bottom=130;edge=1;font=logfont (h=-29); multiline=1;z=4 };static={cls= "Static"; text= "+"; left=14;top=91;right=62;bottom=126;align= "center"; Center=1;font=logfont (h=-29) ; transparent=1;z=5};sum={cls= "edit"; Left=72;top=204;right=188;bottom=242;edge=1;font=logfont (h=-29); multiline= 1;z=2})/*}}*/var code = string.load ("add.py");p y3.exec (code);p y3.exec (code); __main__ = Py3.addmodule ("__main__"); Create the Module object var i =0; for (i=1;50;1) {winform.equal.text=winform.equal.text+ "-"} Winform.button.oncommand = function (ID, Event) {//winform.msgbox (winform.button.text); var n1=tonumber (Winform.n1.text); var n2=tonumber (winform.n2. text); var s = tonumber (__main__.add (N1,N2)); Winform.sum.text=s;} Winform.show () win.loopmessage ();
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.