0% found this document useful (0 votes)
34 views

GUI Scripts and Packs

The document compares several Python GUI frameworks by providing code samples and the interface results for each one. The frameworks included are Tkinter, Flexx, CEF Python, Kivy, PyForms, PyQt, wxPython, PyAutoGUI, and PySimpleGUI. For each one, a short code example is given demonstrating basic interface elements, followed by a 1-sentence description of the resulting interface.

Uploaded by

Raphael Franco
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

GUI Scripts and Packs

The document compares several Python GUI frameworks by providing code samples and the interface results for each one. The frameworks included are Tkinter, Flexx, CEF Python, Kivy, PyForms, PyQt, wxPython, PyAutoGUI, and PySimpleGUI. For each one, a short code example is given demonstrating basic interface elements, followed by a 1-sentence description of the resulting interface.

Uploaded by

Raphael Franco
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Tkinter-----------------------

pip install tkinter

import tkinter
tkinter._test()

Result:

Interface -
Top bar "tk",
linhas = 2,
botton = 2 "Click me!", "Quit"

FLEXX--------------------------

pip install flexx

import flexx

from flexx import flx


class Exemplo(flx.Widget):

def init(self):
flx.Button(text='Olá')
flx.Button(text='Mundo')

if __name__ == '__main__':
a = flx.App(Exemplo, title='Flexx demonstração')
m = a.launch()
flx.run()

Result:

Interface;
Buttons = 2('Olá', 'Mundo')

CEF python---------------------

pip install cefpython3

from cefpython3 import cefpython as cef


import platform
import sys
def main():
check_versions()
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url=" https://www.google.com/",window_title="Olá, mundo!
Este é o primeiro exemplo do CEF python")
cef.MessageLoop()
cef.Shutdown()

def check_versions():
ver=cef.GetVersion()
print("[hello_world.py] CEF python {ver}".format(ver=ver["version"]))
print("[hello_world.py] Chromium {ver}".format(ver=ver["chrome_version"]))
print("[hello_world.py] CEF {ver}".format(ver=ver["cef_version"]))
print("[hello_world.py] python {ver}\
{arch}".format(ver=platform.python_version(),arch=platform.architecture()[0]))
assert cef.__version__>= "57.0", "CEF python v57.0+ required to run this"

if __name__ == '__main__':
main()

Result:

Caixa de dialogo na barra superior do google chrome.

Kivy-----------------------------

from kivy.app import App


from kivy.uix.button import Button

class ExemploApp(App):
def build(self):
return Button(text='DAMADORI IS WATCHING YOU!')

ExemploApp().run()

Result:
Interface;
Caixa de dialogo com uma uma msg centralizada.

Pyforms--------------------------

import pyforms
import OpenGL # Se nao "No module named 'OpenGL_accelerate
from pyforms.basewidget import BaseWidget
from pyforms.controls import ControlText
from pyforms.controls import ControlButton

class ExemploSimples(BaseWidget):

def __init__(self):
super(ExemploSimples,self).__init__('ExemploSimples')
#Definition of the forms fields
self._nome = ControlText('Nome', 'Default value')
self._sobrename = ControlText('Sobrenome')
self._nomeCompleto = ControlText('Nome completo')
self._button = ControlButton('Pressione o Botão')

#Execute the application


if __name__ == "__main__":
from pyforms import start_app
start_app(ExemploSimples)
Resultado:

Caixa de dialogo perguntando nome, sobre nome e nome completo.

PyQt-------------------------------------------

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize

class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)

self.setMinimumSize(QSize(280, 120))
self.setWindowTitle("Olá, Mundo! Exemplo PyQT5")

centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)

gridLayout = QGridLayout(self)
centralWidget.setLayout(gridLayout)

title = QLabel("Olá Mundo para PyQt", self)


title.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(title, 0, 0)

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
sys.exit( app.exec_() )

Result:

Caixa de dialogo com barra superior prenchida com string


E o centro da caixa exibindo "text"

wxPython--------------------

import wx
class Janela(wx.Frame):
def __init__(self, parent, title):
super(Janela, self).__init__(parent, title=title, size = (400,300))
self.panel = ExemploPainel(self)
self.text_ctrl = wx.TextCtrl(self.panel, pos=(5, 5))
self.btn_test = wx.Button(self.panel, label='Pressione esse componente!',
pos=(5, 55))

class ExemploPainel(wx.Panel):
def __init__(self, parent):
super(ExemploPainel, self).__init__(parent)

class ExemploApp(wx.App):
def OnInit(self):
self.frame = Janela(parent=None, title="Janela wxPython")
self.frame.Show()
return True

app = ExemploApp()
app.MainLoop()

Result:

Interface com: Janela nomeada no topo,


e um botton para clicar.

PyAutoGUI-------------------

import pyautogui
screenWidth, screenHeight = pyautogui.size()
currentMouseX, currentMouseY = pyautogui.position()
pyautogui.moveTo(100, 150)
pyautogui.click()
pyautogui.click(100, 200)
pyautogui.move(0, 10)
pyautogui.doubleClick()
pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)
pyautogui.write('Olá, Mundo!', interval=0.25)
pyautogui.press('esc')
pyautogui.keyDown('shift')
pyautogui.press(['left', 'left', 'left', 'left'])
pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl', 'c')
pyautogui.alert('Esta é a mensagem para Tela.')

Result:

Inetrage com a tela do SO, digita "Ola mundo" e abre uma


caixa de dialogo no meio da tela com amsg da linha 16.

PySimpleGUI---------------------------

import PySimpleGUI as sg

sg.theme('DarkAmber')

layout = [
[sg.Text('Texto na linha 1')],
[sg.Text('Entre com um texto na linha 2'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Cancel')]
]
window = sg.Window('Bem-Vindo ao PySimpleGUI', layout)

while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
break
print('Você entrou com:', values[0])

window.close()

Result: Cria uma caixa de dialogo PySimpleGUI:

Texto na linha 1
Entre com um texto na linha 2; <Espaço em branco>
Botoons: Ok / Cancel

You might also like