Tuesday, December 31, 2013

Install PySide for Python 3 on Raspberry Pi

Enter the command to install PySide for Python 3:

$ sudo apt-get install python3-pyside

In Python 3, or IDLE3, enter:

import PySide

If no error reported, means PySide installed successfully. To check the installed version of PySide, enter:

PySide.__version__

Enter "Hello World" of Python 3 with PySide.
#!/usr/bin/python3

import sys
from PySide.QtCore import *
from PySide.QtGui import *

app = QApplication(sys.argv)
label=QLabel("Hello World")
label.show()
app.exec_()
sys.exit()

PySide for Python 3
PySide for Python 3




Related: Install PySide for Python 2 on Raspberry Pi

Install PySide for Python 2 on Raspberry Pi

PySide is an open source software project providing Python bindings for the Qt framework. To install PySide for Python 2 on Raspberry Pi, enter the command:
$ sudo apt-get install python-pyside

In Python, or IDLE, enter:

import PySide

If no error reported, means PySide installed successfully.
To check the installed version of PySide, enter:

PySide.__version__

Currently, version 1.1.1 installed.


"Hello World" of PySide for Python

Create a py module with the code, and run it.
#!/usr/bin/python

import sys
from PySide.QtCore import *
from PySide.QtGui import *

app = QApplication(sys.argv)
label=QLabel("Hello World")
label.show()
app.exec_()
sys.exit()

"Hello World" of PySide for Python
"Hello World" of PySide for Python





Related: Install PySide for Python 3 on Raspberry Pi

Java exercise: Schedule tasks run in a background thread using java.util.Timer

This example run a background task repeatly in 5 seconds to print system time.
java.util.Timer
Example of using java.util.Timer
import java.util.Timer;
import java.util.TimerTask;
import java.io.IOException;
import java.util.Date;

/**
 * @web helloraspberrypi.blogspot.com
 */
class testTimer{

    public static void main(String[] args) {
        Timer timer = new Timer(); 
        TimerTask timeTask = new TimerTask() {
            
            @Override
            public void run() {
                System.out.println((new Date()).toString());
            }
        };
        timer.schedule(timeTask, 0, 5000);
        
        System.out.println("Press ENTER to exit");
        
        try{
            System.in.read();
        }catch(IOException ex){
            System.out.println(ex.toString());
        }
        
        System.out.println("-BYE-");
        timer.cancel();
    }
}