python Tk 输出问题请教
Hi all:python新手,想写一个基于Tk的图形界面东东。主要功能是查询大酒神(dota- -)优酷视频更新情况的,现在遇到一点问题,想请教一下各位大大。。运行环境:win7IDE,源码图如下:
Pyinstaller打包成exe后,运行正常,但是单机button之后,输出是由一个py解释器生成的,我的目标是想输出在Tk的界面中。。。
运行如下:
请问:我该如何修改呢?或者我该查哪个方面的资料呢?
先谢啦 # -*- coding: utf-8 -*-
import urllib
from Tkinter import *
import re
def getupdates():
url = 'http://i.youku.com/u/UMzE2OTY2NjUy'
data = urllib.urlopen(url)
num_pattern = 'videos">.(?P<num>\d{2,4}).'
time_pattern = 'c_time="(?P<time>\d{4}-\d{2}-\d{2}\s\d{2}.\d{2}.\d{2})'
video_name_pattern = 'replace="false"'
for line in data.readlines():
line = line.strip().decode('utf8')
try:
num = re.search(num_pattern,line)
time = re.search(time_pattern,line)
video = re.search(video_name_pattern,line)
if num:
b = int(num.group('num'))
print u'大酒神共有%d个视频' % b
elif time:
print time.group('time')
elif video:
a = line.find('title')
print line
except:
pass
tk = Tk()
tk.title('09 dota update')
tk.geometry('600x600')
Label(tk,text = 'this is used for collecting 09 dota video updates').pack()
Button(tk,text = 'get the result',command = getupdates).pack()
tk.mainloop() 用Label即可,这段代码是python3的。# -*- coding: utf-8 -*-
import urllib.request
from tkinter import *
import re
def getupdates():
url = 'http://i.youku.com/u/UMzE2OTY2NjUy'
data = urllib.request.urlopen(url)
num_pattern = 'videos">.(?P<num>\d{2,4}).'
time_pattern = 'c_time="(?P<time>\d{4}-\d{2}-\d{2}\s\d{2}.\d{2}.\d{2})'
video_name_pattern = 'replace="false"'
for line in data.readlines():
line = line.strip().decode('utf8')
try:
num = re.search(num_pattern,line)
time = re.search(time_pattern,line)
video = re.search(video_name_pattern,line)
if num:
b = int(num.group('num'))
Label(tk,text = '大酒神共有%d个视频'%b).pack()
elif time:
Label(tk, text = time.group('time')).pack()
elif video:
a = line.find('title')
Label(tk, text = line).pack()
except:
pass
tk = Tk()
tk.title('09 dota update')
tk.geometry('600x600')
Label(tk,text = 'this is used for collecting 09 dota video updates').pack()
Button(tk,text = 'get the result',command = getupdates).pack()
tk.mainloop() 不知道大酒神看到此贴会滋生出如何的情愫来.... 非常感谢!已经解决啦~~~:D 回复 3# ssfjhh
哈哈,我是9神脑残粉回复 4# b4and5
1. 在主循环的Button后面,增加一个Text控件。txt = Text(tk)
txt.pack()2. 在函数getupdates()中,print改为:txt.insert(END, '大酒神共有%d个视频' % b)
...
txt.update()
页:
[1]