1 說明
1.1 github
/file/2020/05/06/20200506170556_8583.jpg #或者這個
1.2 安裝
安裝pip install guizero#pip3.8 install guizero #本機安裝
1.3 優點:動態gif圖片的顯示
1.4 測試:本機python3.8,deepin-linux,微軟vscode編輯器
2 最簡單的一個視窗
#方法一from guizero import Appapp = App() #預設大小,標題,位置#app = App(title="Hello world",width=800, height=800) #指定標題和大小app.display()'''#方法二from guizero import * #裡面有很多控制元件,一起匯出,比如App,Box,Windowapp = App() #預設大小,標題,位置app.display()'''
圖
3 小部件學習
3.1 Text部件
from guizero import * #Textapp = App() #預設大小,標題,位置#welcome_message = Text(app, text="Welcome to my app") #預設位置居中頂格和大小#頂左側中間:align="left",align="center",注意沒有center#right和top,bottom等等, height=1大小決定是不是往下,也就是與頂格線的距離welcome_message = Text(app, text="Welcome to my app",align="top", height=1)app.display()
from guizero import *app = App(title="guizero")intro = Text(app, text="Have a go with guizero and see what you can create.")def tuichu(): #app視窗銷燬,就是退出 app.destroy()#定義ok按鈕的功能,可以自定義ok = PushButton(app, text="Ok",command=tuichu)app.display()
3.3 彈出框:
3.3.1 yesno(詢問窗)
3.3.2 question(輸入回答窗)
from guizero import App, PushButton, Textdef button_pressed(): name = app.question("Hello", "What's your name?") if name is not None: #顯示 hello.value = "Hello " + nameapp = App()button = PushButton(app, command=button_pressed, text="Hello")hello = Text(app)app.display()
圖
3.3.3 alert(警示窗)
from guizero import Appapp = App()#帶圖示的app.info("Info", "This is a guizero app")app.error("Error", "Try and keep these out your code...")app.warn("Warning", "These are helpful to alert users")app.display()
圖
4 優點:gif的動態圖片顯示
#from guizero import App, Picture, PushButton, infofrom guizero import *app = App()#方法一#anim = Picture(app, "yytd.gif") #預設大小#可自定義顯示gif的圖的大小#anim.width = 400#anim.height = 400#方法二button = PushButton(app, command=info, args=["button", "you pushed the image"], image="yytd.gif")#button.width = 400#button.height = 400app.display()
5 倒數計時器:
#from guizero import App, Text, PushButton #我討厭這樣from guizero import *app = App("timer")def count_down(): timer.value = int(timer.value) - 1 ''' #這個判斷等於0時,繼續重複倒數計時 if timer.value == "0": # cancel counter timer.cancel(count_down) # reset counter timer.value = 10 # setup repeat,每隔1秒 timer.repeat(1000, count_down) ''' #這是我改進的,注意如果這裡採用app.destroy,那麼 #app=App()就應該放在前面 if timer.value == "0": #自定退出 app.destroy()#app = App("timer") #作者原來放在這裡的timer = Text(app, text="10")timer.repeat(1000, count_down)app.display()
=========未完待續===========
最新評論