# sample code from programing ruby, page 250
require 'tk'
class gifviewer
def initialize(filelist)
setup_viewer(filelist)
enddef run
tk.mainloop
enddef setup_viewer(filelist)
@root = tkroot.new
frame = tkframe.new(@root)
image_w = tkphotoimage.new
tklabel.new(frame) do
image image_w
pack 'side'=>'right'
endlist_w = tklistbox.new(frame) do
selectmode 'single'
pack 'side' => 'left'
endlist_w.bind("buttonrelease-1") do
busy do
filename = list_w.get(*list_w.curselection)
tmp_img = tkphotoimage.new
scale = tmp_img.height / 100
scale = 1 if scale < 1
image_w.copy(tmp_img, 'subsample' => [scale, scale])
image_w.pack
endend
filelist.each do |name|
list_w.insert('end', name) # insert each file name into the list
endscroll_bar = tkscrollbar.new(frame) do
command
pack 'side' => 'left', 'fill' => 'y'
endlist_w.yscrollcommand
frame.pack
end# run a block with a 'wait' cursor
def busy
@root.cursor "watch" # set a watch cursor
yield
ensure
@root.cursor "" # back to original
endend
viewer = gifviewer.new(dir["h:/ͼƭ/qqgif/*.gif"])
viewer.run
Tk庫的使用 1
to change this template,choose tools templates and open the template in the editor.sample code from programing ruby,page 248 require tk class draw def...
TK1 的環境配置
在頁面中做如下選擇,可以過濾出上面的2種包 product jetson tk1 hardware 全選 tools setup 其餘項 不選 接下來按照文章 種的描述進行刷機。安裝參考 參考 把tk1的解析度設定為1024 768,再連線hdmi顯示屏,即可。問題 連線hdmi顯示屏後,重啟tk1...
爬蟲 urllib2庫的使用
所謂網頁抓取,就是把url位址中指定的網路資源從網路流中讀取出來,儲存到本地。在python中有很多庫可以用來抓取網頁,我們先學習urllib2。urllib2 官方文件 urllib2 原始碼 urllib2在 python3.x 中被改為urllib.request 我們先來段 urllib2 ...