Pages

Se afișează postările cu eticheta GUI. Afișați toate postările
Se afișează postările cu eticheta GUI. Afișați toate postările

luni, 4 iunie 2018

PyGame : First interface - part 8.

The PyGame - first interface is a series of python tutorials using PyGame python module and other python modules that help us create a good interface.
If you look at the Wikipedia website then the first phrase is clear:
  In computing, an interface is a shared boundary across which two or more separate components of a computer system exchange information.
Today I will start with ThorPy python module.
This python module comes with the version 1.5.9.
You can read more about this python and test examples at the official webpage.
You can install this python module with the pip tool:

c:\Python364\Scripts>pip install thorpy
Collecting thorpy
  Downloading https://files.pythonhosted.org/packages/09/aa/...
.../thorpy-1.6.tar.gz (373kB)
    100% |████████████████████████████████| 378kB 374kB/s
<5 .10="" python_version=""><2 .0.0=""><2 .0.0="">...
Installing collected packages: thorpy
Successfully installed thorpy-1.6

This is the result of submenus from official website.

joi, 15 august 2013

PyGame : Working with Pygame Subset for Android.

This is an old tutorial I make for PGS4A - Pygame Subset for Android
I tried to rebuild this python module but it does not exist.
For me, it is the end of this series of tutorials.
Read this tutorial if you have PGS4A.

I use the python pygame script from here.
I don't add anything to the script and it's working very well on my tablet.
Many users tell us to use something like that:
import android
android.init()
I don't use this just the python script from my example.
First, after you download and unarchive the PGS4A - Pygame Subset for Android go to in folder and will see these files:
usertest@home:~/pgs4a-0.9.6$ ls
android.py  blacklist.txt       doc               private         src
assets      buildlib            libs              python-install  templates
bin         default.properties  local.properties  res             whitelist.txt
Now you need to test it if is working well...
usertest@home:~/pgs4a-0.9.6$ ./android.py test

All systems go!

... and install the Android SDK. You will need to give all the answers is need it.
usertest@home:~/pgs4a-0.9.6$ ./android.py installsdk

I'm compiling a short test program, to see if you have a working JDK
on your system.


The JDK is present and working. Good!


I'm downloading Apache Ant. This might take a while.


I'm extracting Apache Ant.


I've finished unpacking Apache Ant.


Opening http://developer.android.com/sdk/terms.html in a web browser.


Do you accept the Android SDK Terms and Conditions?
yes/no&gt; yes

I'm downloading the Android SDK. This might take a while.

Created new window in existing browser session.

I'm extracting the Android SDK.


I've finished unpacking the Android SDK.


I'm about to download and install the required Android packages. This
might take a while.

Refresh Sources:
  Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
  Validate XML
  Parse XML
  Fetched Add-ons List successfully
  Refresh Sources
  Fetching URL: https://dl-ssl.google.com/android/repository/repository-7.xml
  Validate XML: https://dl-ssl.google.com/android/repository/repository-7.xml
....
    Starting ADB server succeeded.
  Done. 5 packages installed.

I'm updating the library packages.

Updated local.properties
No project name specified, using project folder name 'library'.
If you wish to change it, edit the first line of build.xml.
Added file android-sdk/extras/google/play_licensing/library/build.xml
Added file android-sdk/extras/google/play_licensing/library/proguard-project.txt
Updated local.properties
No project name specified, using project folder name 'downloader_library'.
If you wish to change it, edit the first line of build.xml.
Added file android-sdk/extras/google/play_apk_expansion/downloader_library/build.xml
Added file android-sdk/extras/google/play_apk_expansion/downloader_library/proguard-project.txt

I've finished installing the required Android packages.


I can create an application signing key for you. Signing an
application with this key allows it to be placed in the Android Market
and other app stores.

Do you want to create a key?
yes/no&gt; yes

I will create the key in the android.keystore file.

You need to back this file up. If you lose it, you will not be able to
upgrade your application.

You also need to keep the key safe. If evil people get this file, they
could make fake versions of your application, and potentially steal
your users' data.

Will you make a backup of android.keystore, and keep it in a safe
place?
yes/no&gt; yes

Please enter your name or the name of your organization.
&gt; free-tutorials.org

I've finished creating android.keystore. Please back it up, and keep
it in a safe place.


It looks like you're ready to start packaging games.
After that let's see the files we have it...
usertest@home:~/pgs4a-0.9.6$ ls
android.keystore             bin                    local.properties
android.py                   blacklist.txt          private
android-sdk                  buildlib               python-install
android-sdk_r20-linux.tgz    default.properties     res
apache-ant                   doc                    src
apache-ant-1.8.4-bin.tar.gz  libpeerconnection.log  templates
assets                       libs                   whitelist.txt
My pygame script is located in ~/Dropbox/AndroidApp/pygame-android/test001.
How I make the android application? First I configure the application. You need to give all answers when use configures args...
usertest@home:~/pgs4a-0.9.6/bin$ ./android.py configure ~/Dropbox/AndroidApp/pygame-android/test001
... next, I build it.
If you use: install then will expect the emulator or device to install it. I don't use install, just release.
usertest@home:~/pgs4a-0.9.6/bin$ ./android.py build ~/Dropbox/AndroidApp/pygame-android/test001 release
After that will see in the bin folder your android pygame application.
usertest@home:~/pgs4a-0.9.6/bin$ ls
AndroidManifest.xml    classes.dex.d  test001-1.ap_.d
AndroidManifest.xml.d  jarlist.cache  test001-1-release.apk
build.prop             proguard.txt   test001-1-release-unaligned.apk
classes                res            test001-1-release-unsigned.apk
classes.dex            test001-1.ap_  test001-1-release-unsigned.apk.d
Let's see how is working...

PyGame : First interface - part 4.

This is another tutorial about pygame.
The main goal of this tutorial is to make one box with some text for your application or game.
First, I import the pygame module and I set two colors: black and green:
import pygame
import pygame.font
import pygame.event
import pygame.draw
import string
from pygame.locals import *
black=(0,0,0)
green=(0,255,0)
Tne next step is to make a function to create the display box.
def display_box(screen,mess):
        fontobject = pygame.font.Font(None,18)
        pygame.draw.rect(screen,black,((screen.get_width() / 2) - 100,
                (screen.get_height() / 2) - 10,200,20), 0)
        pygame.draw.rect(screen,green,((screen.get_width() / 2) - 101,
                (screen.get_height() / 2) - 11,200,20), 1)
        if len(mess) != 0:
                screen.blit(fontobject.render(mess, 1, (25,255,25)),
                ((screen.get_width() / 2) - 100, (screen.get_height() / 2) - 9))
        pygame.display.flip()
Let's start the pygame window and display the box.
if __name__ == '__main__':
        pygame.init()
        pygame.display.set_caption("Hello world")
        screen = pygame.display.set_mode((320,240))
        pygame.font.init()
        mess = []
        while 1:
                display_box(screen,"Hello world text")
                pygame.display.update()
                pygame.time.delay(10)
                for event in pygame.event.get():
                        if event.type in (pygame.QUIT,pygame.KEYDOWN,pygame.MOUSEBUTTONDOWN):
                                raise SystemExit
The result of this source of code can be seen in the next image.

You can also change this source of code to make editbox or other GUI elements.