#-- coding: utf-8 --
# 你好,改的地方我都注释了。
# 如果有不对的地方请高手指点。
from Tkinter import
def counter(btn): #增加一个参数把button对象传入,用来更改它的文字
global count
a = count
i=int(a)
i+=1
a=str(i)
count = a
btnconfig(text = a) #增加了这一句,更新button上的文本内容
window = Tk()
frame = Frame(window)
framepack()
#global count
count = StringVar()
count = '0'
botton = Button(frame,text = count ,command = lambda:counter(botton)) #因为事件触发的函数(callback)需要有参数传进入,所以用lambda表达式
# 可以参考下这里:http://blogsinacomcn/s/blog_ac9fdc0b0101n9u6html
# 其实用bind也可以进行事件触发的绑定。
print(count)
bottonpack()
windowmainloop()
你的要求很模糊,你不太了解python吧?
只能大概写一下。
import Tkinter
def file_path(file_name):
print file_name
root = TkinterFrame()
rootmastertitle('title')
a=TkinterButton(root, text="Change",command=lambda: file_path('axls'))
apack()
rootpack()
from tkinter import
import time
#Style of Progressbar
class Progressbar(Canvas, object):
def __init__(self, master, length=630):
selfsum_length = length
super(Progressbar, self)__init__(master, width=selfsum_length, height=5, bg='white')
self_master = master
selfcanvas_shape = selfcreate_rectangle(0, 0, 0, 25, fill='#1E90FF')
selfcanvas_text = selfcreate_text(292, 4, anchor=NW)
def update_progress_bar(self, percent=100):
selfhour = int(percent / 3600)
selfminute = int(percent / 60) - selfhour 60
selfsecond = percent % 60
selfgreen_length = int(selfsum_length percent / 100)
selfcoords(selfcanvas_shape, (0, 0, selfgreen_length, 25))
selfitemconfig(selfcanvas_text, text='%02d:%02d:%02d' % (selfhour, selfminute, selfsecond))
def pack(self, args, kwargs):
super(Progressbar, self)pack(args, kwargs)
def grid(self, args, kwargs):
super(Progressbar, self)grid(args, kwargs)
def place(self, args, kwargs):
super(Progressbar, self)place(args, kwargs)
def forget(self, args, kwargs):
super(Progressbar, self)place_forget(args, kwargs)
class Progressbar_loding(Canvas, object):
def __init__(self, master, length=630):
selfsum_length = length
super(Progressbar_loding, self)__init__(master, width=selfsum_length, height=5, bg='white')
self_master = master
selfcanvas_shape = selfcreate_rectangle(0, 0, 0, 25, fill='#1E90FF')
selfcanvas_text = selfcreate_text(292, 4, anchor=NW)
def update_progress_bar_1(self, percent=100):
selfgreen_length = int(selfsum_length percent / 100)
selfcoords(selfcanvas_shape, (selfsum_length, 0, selfgreen_length, 25))
def update_progress_bar_2(self, percent=100):
selfgreen_length = int(selfsum_length percent / 100)
selfcoords(selfcanvas_shape, (0, 0, selfgreen_length, 25))
def update_progress_bar(self, timer=001):
for x in range(0, 101):
selfupdate_progress_bar_2(x)
timesleep(timer)
for x in range(0, 101):
selfupdate_progress_bar_1(x)
timesleep(timer)
def pack(self, args, kwargs):
super(Progressbar_loding, self)pack(args, kwargs)
def grid(self, args, kwargs):
super(Progressbar_loding, self)grid(args, kwargs)
def place(self, args, kwargs):
super(Progressbar_loding, self)place(args, kwargs)
def forget(self, args, kwargs):
super(Progressbar_loding, self)place_forget(args, kwargs)
直接附代码
Tkinter居然没有这种组件,所以就只能模拟了
#! /usr/bin/python# -- coding: utf8 --
from Tkinter import
class Select(Frame):
def __init__(self, master=None):
Frame__init__(self, master)
selflabel = Label(self, text="选择项目")
selflistBox = Listbox(self, height=1)
selfbutton = Button(self, text='V', command=selftriggle)
selfhideList = True
for i in xrange(10):
selflistBoxinsert(i, 'Item%d'%i)
selflabelgrid(row=0, column=0, sticky=N)
selflistBoxgrid(row=0, column=1, sticky=N)
selfbuttongrid(row=0, column=2, sticky=N)
selfgrid()
def triggle(self):
selfhideList ^= 1
selflistBoxconfig(height=[selflistBoxsize(), 1][selfhideList])
app = Select()
appmainloop()
仅供参考。
不懂,一起学习。
我修改了下你的code,
# ActivePython 27import threading
import Tkinter
import time
class mapthread(threadingThread):
def run(self):
selfgame()
def game(self):
while 1:
print 'GAME'
timesleep(1)
class helpthread(threadingThread):
def run(self):
selfhelp()
def help(self):
t=TkinterTk()
f=TkinterFrame(t,width=200,height=200)
l=TkinterLabel(f,text='XXYYZZ')
fpack(fill=TkinterBOTH, expand=1)
lpack(fill=TkinterBOTH, expand=1)
tmainloop()
t1=mapthread()
t2=helpthread()
t2start()
t1start()
执行后,可以显示窗口。
你是通过python_run调用么?
你把python安装目录下Tkinterpy、FixTkpy、_tkinterpyd三个文件(具体位置搜索即可)拷贝到Marc安装目录下shlib文件夹相应位置,应该可以的。
Tkinter是图形模块吧,不知道二次开发程序用此模块做何用途。
欢迎分享,转载请注明来源:表白网
评论列表(0条)