日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python哨兵循环_Python:deadloop之非模态交互界面(模态循环)(哨兵循环)

發布時間:2025/4/5 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python哨兵循环_Python:deadloop之非模态交互界面(模态循环)(哨兵循环) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

deadloop之非模態交互界面(模態循環)(哨兵循環)

通過無限循環,條件退出,實現多模態的交互界面

主要功能1:通過鍵盤按鍵g\w\r\b進行界面顏色改變,按q退出

主要功能2:點擊界面某處生成輸入框,回車使輸入框內的文字固定在界面

當等待一個特殊的鍵入時可用,(以return為例)

while win.getkey() != 'Return':

pass

#我的菜雞簡略版本

from graphics import *

win = GraphWin('Click and Type', 500, 500)

while True:

keyout = win.checkKey()

if keyout == 'q':

break

elif keyout == 'r':

win.setBackground('pink')

elif keyout == 'w':

win.setBackground('white')

elif keyout == 'b':

win.setBackground('lightblue')

elif keyout == 'g':

win.setBackground('lightgray')

pt = win.checkMouse()

if pt:

entry = Entry(pt, 5)

entry.draw(win)

while True:

key = win.checkKey()

if key == 'Return':

break

elif key:print(key)

entry.undraw()

text = entry.getText()

Text(pt, text).draw(win)

# 教材版本(不同功能函數定義調用)

# event_loop2.py --- color-changing window

from graphics import *

def handleKey(k, win):

if k == 'r':

win.setBackground('pink')

elif k == 'w':

win.setBackground('white')

elif k == 'g':

win.setBackground('lightgray')

elif k == 'b':

win.setBackground('lightblue')

def handleClick(pt, win):

# create an Entry for user to type in

entry = Entry(pt, 10)

entry.draw(win)

# Go modal: loop until user types key

while True:

key = win.getKey()

if key == 'Return': break

else:print(key)

# undraw the entry and create and draw Text.

entry.undraw()

typed = entry.getText()

Text(pt, typed).draw(win)

# clear (ignore) ang mouse click that occurred during text entry

win.checkMouse()

def main():

win = GraphWin('Click and Type', 500, 500)

# Event loop: handle presses and mouse clicks until the user

# press the 'q' key.

while True:

key = win.checkKey()

if key == 'q': # loop exit

break

if key:

handleKey(key, win)

pt = win.checkMouse()

if pt:

handleClick(pt, win)

win.close()

main()

運行效果:

總結

以上是生活随笔為你收集整理的python哨兵循环_Python:deadloop之非模态交互界面(模态循环)(哨兵循环)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。