p=Tkinter.PhotoImage(file=sys.path[0]+'\\1.gif')
l = Tkinter.Label(topwin,image=p).pack()
l.image = p # 這句不能少,否則圖片不顯示
2. python tkinter 如何做一個如下所示的下拉菜單
Tkinter居然沒有這種組件,所以就只能模擬了
#! /usr/bin/python
# -*- coding: utf8 -*-
from Tkinter import *
class Select(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.label = Label(self, text="選擇項目")
self.listBox = Listbox(self, height=1)
self.button = Button(self, text='V', command=self.triggle)
self.hideList = True
for i in xrange(10):
self.listBox.insert(i, 'Item%d'%i)
self.label.grid(row=0, column=0, sticky=N)
self.listBox.grid(row=0, column=1, sticky=N)
self.button.grid(row=0, column=2, sticky=N)
self.grid()
def triggle(self):
self.hideList ^= 1
self.listBox.config(height=[self.listBox.size(), 1][self.hideList])
app = Select()
app.mainloop()
僅供參考。
3. Python Tkinter 大神請進!
因為你在循環里創建,最後button存儲的是第三次的,所以點擊後只有第三個變化。
可以這樣
button = Button(window)
button['text'] = 'one'
button.bind('<Button-1>', self.changed)
def changed(self, event):
if event.widget['text'] == 'one':
event.widget['text'] = 'two'
else:
event.widget['text'] = 'one'
4. python3.0 tk的使用
有什麼問題嗎 ,剛好之前寫過一些關於py3 tk的東西,可以一起探討一下,給你一個例子:
importurllib,urllib.request
importos,re
fromtkinterimport*
importtkinter.ttk
importctypes
importthreading,time
defRunApp():
handler=None;
operator="open";
fpath="D:SoftWareChromeChromechrome.exe";
param='-user-data-dir="D:SoftWareChromeprofil';
dirpath='D:SoftWareChromeChrome';
ncmd=1;
shell32=ctypes.windll.LoadLibrary("shell32.dll");
shell32.ShellExecuteW(handler,operator,fpath,param,dirpath,ncmd);
defcallbackfunc(blocknum,blocksize,totalsize):
'''回調函數
@blocknum:已經下載的數據塊
@blocksize:數據塊的大小
@totalsize:遠程文件的大小
'''
percent=100.0*blocknum*blocksize/totalsize
ifpercent>100:
percent=100
prb['value']=percent
lbjd['text']='更新進度%0.2f'%percent+'%'
#print(percent)
defprbadd():
prb['value']+=1
defLoad():
time.sleep(0.5)
t1=threading.Thread(target=down)
t1.start()
defdown():
nfn=vel+'_chrome_installer.exe'
print('hehe')
urllib.request.urlretrieve(link,nfn,callbackfunc)
os.system('update.bat'+nfn)
#print('更新完成')
#os.system('PAUSE')
#os.system('''startD:SoftWareChromeChromechrome.exe-user-data-dir="D:SoftWareChromeprofil"''')
RunApp()
root.quit()
html=urllib.request.urlopen('http://down.tech.sina.com.cn/page/40975.html').read().decode('gbk')
t=re.search('(?<=down_load_url"href=")[^"]+(?="target="_blank"class="f14b">正式版-)',html)
link='http://down.tech.sina.com.cn'+t.group(0)
title=html[html.index('<title>')+7:html.index('</title>')]
vel=title[title.rindex('/')+1:title.index('】')-3]
ls=os.listdir('../Chrome/')
forfninls:
iffn.find('exe')==-1:
oldvel=fn
break
ifoldvel!=vel:
root=Tk()
root.title('Chrome更新工具')
#root.attributes("-toolwindow",1)
lbjd=Label(root,text='更新進度')
lbjd.pack()
prb=tkinter.ttk.Progressbar(root,length=400,maximum=100.0,value=0)
prb.pack()
sw=root.winfo_screenwidth()
sh=root.winfo_screenheight()
root.geometry('410x50+'+str(int((sw-410)/2))+'+'+str(int((sh-50)/2)))
#root.bind('<Visibility>',Load)
Load()
root.mainloop()
else:
#print('已經是最新版本')
RunApp()
#os.system('''startD:SoftWareChromeChromechrome.exe-user-data-dir="D:SoftWareChromeprofil"''')
#print(title)
這個是我自己更新chrome用的
5. PYTHON tkinter編程,請懂的大俠幫忙!
據說基本上人都在研究pyqt,用tkinter的比較少,所以估計沒幾個人會吧,你再等等看看有沒有人幫你吧,反正我不會
6. python3.6+ tkinter.做的登陸頁面怎樣跳轉到wx.的做的系統頁面,最好有個例子,或者可不可以這樣做
雖然看不懂你說的是什麼 但是你可以看看這個網頁鏈接
7. python3中tkinter.filedialog如何使用
fromtkinter.
fname=askopenfilename(filetypes=(("Templatefiles","*.tplate"),("HTMLfiles","*.html;*.htm"),("Allfiles","*.*")))
8. python 中的tkinter案例嗎
可以的。tkinter最近的版本都支持原生的GUI widget了。界面和C++寫出來的沒差別。
9. python3的tkinter代碼,為什麼會報錯
1、可能是數據類型錯誤,int()接收到一個字元型。或是接收到的是一個浮點型。浮點型需要先轉換。
比如int(10.0)需要改成int(float(10.0))。
2、可能是代碼寫錯了,比如少打了個引號