gui
— Provide related functions of GUI class drawing¶
-
class
gui.
UI
¶
UI class¶
Provide UI interface class controls
-
class
gui.
UI
(oled)
Create UI object.
oled
- Objects coming into the framebuf class, such as mPython OLED display, then OLED object.
-
UI.
ProgressBar
(x, y, width, height, progress)¶
Draw progress bar.
x
、y
- the upper left corner is used as the starting point coordinatewidth
- Progress bar widthheight
- Progress bar heightprogress
- Progress bar percentage
from mpython import *
myUI=UI(oled)
myUI.ProgressBar(30,30,70,8,60)
oled.show()
-
UI.
stripBar
(x, y, width, height, progress, dir=1, frame=1)¶
Draw vertical or horizontal columnar bars
x
、y
- the upper left corner is used as the starting point coordinatewidth
- Column bar widthheight
- Column bar heightprogress
- Column bar percentagedir
- Column bar direction. dir= 1 for horizontal direction, dir= 0 for vertical direction.frame
- When frame=1 , the frame is displayed; when frame=0 , the frame is not displayed.
-
UI.
qr_code
(str, x, y, scale=2)¶ Draw 29*29 QR code
str
- QR code data, type stringx
、y
- the upper left corner is used as the starting point coordinatescale
- amplification scale: can be 1, 2. Default is 2X.
import gui
from mpython import *
ui=gui.UI(oled)
ui.qr_code('https://mpython.readthedocs.io',0,0)
oled.show()
Clock class¶
Provide analog clock display function
-
class
gui.
Clock
(oled, x, y, radius)¶
Create Clock object.
oled
- Objects coming into the framebuf class, such as mPython OLED display, then OLED object。x
、y
- The upper left corner is used as the starting point coordinateradius
- Clock radius
-
Clock.
settime
()¶
Get local time and set analog clock time
-
Clock.
drawClock
()¶
Draw a clock
-
Clock.
clear
()¶
Clear the clock
from mpython import*
from machine import Timer
import time
clock=Clock(oled,64,32,30)
def Refresh():
clock.settime()
clock.drawClock()
oled.show()
clock.clear()
tim1 = Timer(1)
tim1.init(period=1000, mode=Timer.PERIODIC, callback=lambda _:Refresh())
Image¶
Support pbm and bmp 1bit image formats.
-
class
gui.
Image
¶
Create Image object
-
Image.
load
(path, invert=0)¶
Load the pbm or bmp picture format file and return the picture framebuf.FrameBuffer
object.
path
- Picture file pathinvert
- The pixels are inverted. 0 means no reversal, 1 means reverse.
Example:
from mpython import *
from gui import Image
image = Image()
fb = image.load('clown_1.bmp',1 )
oled.blit(fb, 0, 0)
oled.show()