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、可能是代码写错了,比如少打了个引号