# Busy Cursors
本節介紹在應用程序的長時間運行部分中如何更改光標。 更改為繁忙的光標會向應用程序用戶提供一些反饋,否則他們可能會認為該應用程序已掛起,而不執行任何操作。其中一個在支持模塊的模塊級別包含以下代碼:
~~~
# 添加了允許將默認光標更改為繁忙光標的代碼。
# 格雷格·沃爾特斯(Greg Walters)在python編程示例中基于代碼手動添加了變量以指示較長的過程。
# 這些例程也可以在Greyson的pg頁中看到。158。
busyCursor = 'watch'
preBusyCursors = None
def busyStart(newcursor=None):
'''我們首先檢查是否將值傳遞給newcursor。
如果沒有,我們默認使用busyCursor。
然后,我們遍歷busyWidgets元組,并將光標設置為所需的任何內容。'''
global preBusyCursors
if not newcursor:
newcursor = busyCursor
newPreBusyCursors = {}
for component in busyWidgets:
newPreBusyCursors[component] = component['cursor']
component.configure(cursor=newcursor)
component.update_idletasks()
preBusyCursors = (newPreBusyCursors, preBusyCursors)
def busyEnd():
'''在這個例程中,我們基本上將busyWidget元組中的小部件的游標重置為默認游標'''
global preBusyCursors
if not preBusyCursors:
return
oldPreBusyCursors = preBusyCursors[0]
preBusyCursors = preBusyCursors[1]
for component in busyWidgets:
try:
component.configure(cursor=oldPreBusyCursors[component])
except KeyError:
pass
component.update_idletasks()
# 繁忙游標代碼的結尾。
~~~
并將以下代碼行插入支持模塊的“ init”中:
~~~
global busyWidgets
busyWidgets = (top, )
~~~
第一行在函數頂部附近,并且在創建根對象之后插入對busyWidgets的分配。 在我的一個應用程序中,函數“ init”如下所示:
~~~
def init(top, gui):
''' 創建用于定期更新GUI的線程的功能。'''
global t
global w, top_level
global busyWidgets
w = gui
top_level = top
t = threading.Thread(target=fill_window,)
t.start()
busyWidgets = (top, w.Scrolledtext1)
~~~
上面的最后一行將全局變量busyWidgets設置為我希望顯示busy光標的那些小部件的元組。 這是來自示例wcpe的示例,在該示例中,我希望忙碌的光標出現在頂級窗口以及Scrolledtextbox中。當啟動一段可能長時間運行的代碼段(繁忙部分)時,請在開始處插入以下內容:
~~~
busyStart()
~~~
當離開繁忙的部分時,請在最后一個statement()中進行以下操作:
~~~
busyEnd()
~~~
顯然,一個應用程序可能有許多忙碌的部分,它們可能與特定功能一致或不一致。
可以通用使用此代碼以使用任何Tkinter游標。
- 介紹
- 更新記錄
- X Concepts
- Visual Tcl
- 使用PAGE設計范例
- 項目目錄配置
- Python 2 or Python 3
- Python編碼和UTF-8
- 使用PAGE的簡短說明
- PAGE的狀態
- 安裝
- PAGE界面
- 主菜單
- 子菜單
- 組件工具欄
- 屬性編輯器
- 組件樹
- 綁定操作窗口
- 菜單編輯器
- 首選項窗口
- Python控制臺
- 回調窗口
- 應用窗口
- 顏色對話框
- 顏色
- 雙顯示器
- 默認值和首選項
- Preferences Windows
- Color Preferences
- Font Preferences
- 模塊結構
- 風格和主題
- 使用PAGE
- 命名約定
- 概述
- Toplevel Geometry
- 別名
- 氣球幫助-工具提示
- 選擇和修改組件
- 修改組件位置和尺寸
- 鎖定組件
- 填充容器
- 剪切,復制和粘貼
- Stash and Apply - Propagate Widget Options
- 菜單組件
- 回調函數
- 將事件鏈接到回調函數
- 創建綁定
- 為滾動組件創建綁定
- 定義回調函數
- 查看回調
- 指定字體
- Toplevel Widget
- 相對位置
- Tkinter變量類
- Ttk Widgets
- Scrolled Widgets
- Ttk Notebook and PNotebook
- Ttk Panedwindow
- Ttk Treeview
- Entry
- Ttk Entry
- Ttk Combobox
- Radiobuttons
- 文本和變量的奇異性
- Label
- Listbox
- Spinbox
- Scale and TScale
- TSeparator
- Sizegrip
- Custom Widgets
- Canvas
- 生成,檢查和運行Python GUI
- 創建和保存代碼模塊
- 檢查生成的Python模塊
- 執行Python模塊
- 將生成的Python模塊加載到IDE中
- 具有多個頂級Windows的應用程序
- 修改光標
- 使用圖像
- 動態組件
- 菜單
- 重建
- 自動更新支持模塊
- 重用
- 模板
- 從現有項目中借用組件
- 范例
- 結語