Skip to content

User Interface

TheMixRay edited this page Jun 22, 2022 · 2 revisions

Example

import pygwin

win = pygwin.create('UI example',(270,350))
base = pygwin.ui.base(win) # Creating ui base

lbl = pygwin.ui.label('Label') # Creating label
base.put(lbl,(130-(lbl.surface.size[0]/2),10)) # Putting label to base
base.put(pygwin.ui.button('Button',width=250),(10,50)) # Putting button to base
base.put(pygwin.ui.entry('Entry',width=123),(10,100)) # Putting entry to base
base.put(pygwin.ui.keySelect('Key',width=122),(138,100)) # Putting key selector to base
loadbar = pygwin.ui.loadingBar(250,25) # Creating loading bar
base.put(loadbar,(10,150)) # Putting loading bar to base
slider = pygwin.ui.slider(250) # Creating slider
base.put(slider,(10,170)) # Putting slider to base
cb = pygwin.ui.checkBox(25,borderWidth=2) # Creating checkbox
base.put(cb,(10,220)) # Putting checkbox to base
base.put(pygwin.ui.label('Checkbox',20),(45,225)) # Putting checkbox label to base
ta = pygwin.ui.textarea('Textarea',width=250,maxSymbols=20) # Creating textarea
ta.text += '0123456789\n0123456789' # Set text to textarea
ta.focus = True # Focus textarea
ta._generate() # Generate textarea surface
ta.focus = False # Unfocus textarea
base.put(ta,(10,255)) # Putting textarea to base
tta = pygwin.ui.tip('textarea',
                    *ta.surface.size,
                    waitBeforeShowing=30) # Creating textarea tip
base.put(tta,(10,255)) # Putting textarea tip to base

run = True
while run:
    for event in pygwin.getEvents():
        if event.type == pygwin.QUIT:
            run = False
    base.draw() # Drawing base
    if cb.get(): # If checkbox
        loadbar.set(slider.get()) # If checkbox
    else:
        loadbar.step() # Step loading bar
        if loadbar.get() == loadbar.length: # If loading bar is full
            loadbar.set(0) # Reset loading bar
    tta.responceWidth,tta.responceHeight=ta.surface.size # Set responce width, height to textarea tip
    win.update(30)
pygwin.close()

Window

Base

Init

Initialization a base

pygwin.ui.base(win, bg=(128,128,128))
  • win Window/Surface for base
  • bg Background color of base

Returns base

Draw

Draw base

base.draw()

Returns None

Put

Put widget to the base

base.put(widget, (x, y), page=0)
  • widget Widget
  • x Widget x
  • y Widget y
  • page Widget page name

Returns None

Select page

Select local page

base.selectPage(page)
  • page Page name

Returns None

Get page

Get local page

base.getPage()

Returns str

Get widgets

Get page widgets

base.getWidgets(page=0)
  • page Page name

Returns list

Set widget pos

Set widget position.

base.setWidgetPos(index, pos, page=0)
  • index Widget index
  • pos New widget position
  • page Widget page

Returns None

Widget

Init

Initialization a widget

pygwin.ui.widget(surface)
  • surface Surface for widget

Returns widget

Draw

Draw widget.

widget.draw(win, (x, y))
  • win Window/Surface for widget
  • x Widget x
  • y Widget y

Returns None

On/off

On/off widget.

widget.on()
widget.off()

Returns None

Destroy

Destroy widget.

widget.destroy()

Returns None

Config

Configure widget.

widget.config(parameter=value,
              parameter0=value0
              parameter1=value1...)
  • parameter Parameter (ex. surface)
  • value Value (ex. surface((20,21)))

Returns None

Get surface

Get widget surface.

widget.surface

Returns surface

Label

This class inherits the widget class

Init

Initialization a label

pygwin.ui.label(text,size=30,color=(0,0,0),
                font=pygwin.font.defaultFont)
  • text Label text
  • size Font size
  • color Font color
  • font Font

Returns widget

Image

This class inherits the widget class

Init

Initialization a image

pygwin.ui.image(path)
  • path Image path

Returns widget

Button

This class inherits the widget class

Init

Initialization a button

pygwin.ui.button(text,func=lambda:None,fontSize=30,
                 font=pygame.font.defaultFont,
                 width=None,height=None,bg=(70,70,70),
                 fg=(180,180,200),afg=(50,50,50),
                 abg=(200,200,200),borderColor=(50,50,50),
                 borderWidth=5)
  • text Button text
  • func Click callback
  • fontSize Font size
  • font Font
  • width Button width
  • height Button height
  • bg Button background color
  • fg Button font color
  • afg Button active font color
  • abg Button active background color
  • borderColor Border color
  • borderWidth Border width

Returns widget

Entry

This class inherits the widget class

Init

Initialization an entry

pygwin.ui.entry(hint='',fontSize=30,font=_df,
                width=None,height=None,
                bg=(70,70,70),fg=(180,180,200),
                afg=(200,200,200),abg=(50,50,50),
                hintColor=(100,100,100),
                lineColor=(200,200,200),
                borderColor=(50,50,50),
                borderWidth=5,maxSymbols=None,
                whitelist=None,blacklist=[])
  • hint Entry hint
  • fontSize Font size
  • font Font
  • width Entry width
  • height Entry height
  • bg Entry background color
  • fg Entry font color
  • afg Entry active font color
  • abg Entry active background color
  • hintColor Entry hint font color
  • lineColor Entry tick line color
  • borderColor Border color
  • borderWidth Border width
  • maxSymbols Max symbols to insert
  • whitelist Whitelist to insert
  • blacklist Blacklist to insert

Returns widget

Get text

Get text from entry

entry.get()

Returns str

Insert

Insert text to entry

entry.insert(text)
  • text Text

Returns None

Delete

Delete symbols from entry

entry.delete(symbols=1)
  • symbols Symbols count

Returns None

Textarea

This class inherits the widget class

Init

Initialization an textarea

pygwin.ui.textarea(hint='',fontSize=30,
                 font=_df,width=None,bg=(70,70,70),
                 fg=(180,180,200),afg=(200,200,200),
                 abg=(50,50,50),hintColor=(100,100,100),
                 lineColor=(200,200,200),
                 borderColor=(50,50,50),
                 borderWidth=5,maxSymbols=None,
                 whitelist=None,blacklist=[])
  • hint Entry hint
  • fontSize Font size
  • font Font
  • width Entry width
  • bg Entry background color
  • fg Entry font color
  • afg Entry active font color
  • abg Entry active background color
  • hintColor Entry hint font color
  • lineColor Entry tick line color
  • borderColor Border color
  • borderWidth Border width
  • maxSymbols Max symbols to insert
  • whitelist Whitelist to insert
  • blacklist Blacklist to insert

Returns widget

Get text

Get text from textarea

textarea.get()

Returns str

Insert

Insert text to textarea

textarea.insert(text)
  • text Text

Returns None

Delete

Delete symbols from textarea

textarea.delete(symbols=1)
  • symbols Symbols count

Returns None

Key selector

This class inherits the widget class

Init

Initialization an keySelect

pygwin.ui.keySelect(keyBefore='',fontSize=30,
                font=_df,width=None,height=None,
                bg=(70,70,70),fg=(180,180,200),
                afg=(200,200,200),abg=(50,50,50),
                hintColor=(100,100,100),
                lineColor=(200,200,200),
                borderColor=(50,50,50),
                borderWidth=5,maxSymbols=None,
                whitelist=None,blacklist=[])
  • keyBefore Preinserted text
  • fontSize Font size
  • font Font
  • width Key selector width
  • height Key selector height
  • bg Key selector background color
  • fg Key selector font color
  • afg Key selector active font color
  • abg Key selector active background color
  • hintColor Key selector hint font color
  • lineColor Key selector tick line color
  • borderColor Border color
  • borderWidth Border width
  • maxSymbols Max symbols to insert
  • whitelist Whitelist to insert
  • blacklist Blacklist to insert

Returns widget

Get key

Get key from key selector

keySelect.get()

Returns str

Loading bar

This class inherits the widget class

Init

Initialization a loading bar

pygwin.ui.loadingBar(width,
                     height=50,
                     length=100,
                     bg=(70,70,70),
                     loadedColor=(50,200,50),
                     borderColor=(50,50,50),
                     borderWidth=5)
  • width Loading bar width
  • height Loading bar height
  • height Loading bar length
  • bg Loading bar background color
  • loadedColor Color of loaded rect
  • borderColor Border color
  • borderWidth Border width

Returns widget

Step

Step loading bar

loadingBar.step(count=1)
  • count Step count

Returns None

Set loaded

Set loading bar loaded

loadingBar.set(x)
  • x Loaded

Returns None

Get loaded

Get loading bar loaded

loadingBar.get()

Returns int

Reset

Reset loading bar

loadingBar.reset()

Returns None

Slider

This class inherits the widget class

Init

Initialization a slider

pygwin.ui.slider(width,
                 bg=(70,70,70),
                 fg=(50,200,50),
                 horizontal=True)
  • width Slider width/height
  • bg Slider line color
  • fg Slider circle color
  • horizontal Is slider horizontal

Returns widget

Get

Get slider value

slider.get()

Returns int

Set

Set slider value

slider.set(x)
  • x Slider value

Returns None

Checkbox

This class inherits the widget class

Init

Initialization a scroll bar

pygwin.ui.checkBox(width=50,
                   bg=(180,180,180),
                   fg=(50,180,50),
                   afg=(70,200,70),
                   abg=(120,120,120),
                   borderColor=(220,220,220),
                   borderWidth=5)
  • width Checkbox size
  • bg Checkbox background color
  • fg Checkbox font color
  • afg Checkbox active font color
  • abg Checkbox active background color
  • borderColor Checkbox border color
  • borderWidth Checkbox border width

Returns widget

Get

Get checkbox value

checkBox.get()

Returns bool

Set

Set checkbox value

checkBox.set(x)
  • x Checkbox value

Returns None

Tip

This class inherits the widget class

Init

Initialization a tip

pygwin.ui.tip(text,responceWidth,
              responceHeight,fontSize=15,
              font=_df,borderColor=(180,180,50),
              borderWidth=2,bg=(255,255,128),
              fg=(35,35,5),waitBeforeShowing=0,
              tipPosRelativeCursor=(10,10))
  • text Tip text
  • responceWidth The width of the tip response area
  • responceHeight The height of the tip response area
  • font Text font
  • fontSize Font size
  • borderColor Tip border color
  • borderWidth Tip border width
  • bg Tip background color
  • fg Tip font color
  • waitBeforeShowing Time (fps*seconds) before showing the hint
  • tipPosRelativeCursor The position of the hint relative to the mouse cursor

Returns widget

Clone this wiki locally