close
Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": libsvn_fs_base-1.so.1: failed to map segment from shared object: Cannot allocate memory). Look in the Trac log for more information.
- Timestamp:
-
Oct 13, 2010, 11:50:07 AM (14 years ago)
- Author:
-
zsjheng
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v1
|
v1
|
|
| 1 | '''ProgressBar 應用1''' |
| 2 | |
| 3 | 很多人在撰寫PyGtk視窗程式, 在使用到 ProgressBar這個控制項時經常遇到的問題, 就是沒有辦法同步將程式執行的進度(如檔案下載進度, 數學計算進度...等等)更新到PyGtk視窗上的ProgressBar. 以下這個下載檔案的小範例將提供一個利用 thread 來更新ProgressBar進度的方法供讀者參考. (這個程式撰寫方法我是參考一個英文的blog, 不過忘記連結, 之後找到會在補上reference) |
| 4 | |
| 5 | 首先當然要先將處理 thread 的 threading 套件給引入. 另外還必須再引入 gobject 套件, 他提供了完成這個範例程式也必須使用到的一個重要函式. |
| 6 | |
| 7 | {{{ |
| 8 | import gobject |
| 9 | import gtk |
| 10 | import threading |
| 11 | }}} |
| 12 | |
| 13 | 接下來就是先利用 Gtk 控制項兜出一個視窗如下: |
| 14 | [[Image()]] |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | 原始檔下載: [ PB.py] |
| 20 | |
| 21 | 重要參考:[[BR]] |
| 22 | 1. [http://www.pygtk.org/docs/pygtk/class-gtkprogressbar.html PyGtk ProgressBar API] |