本文整理汇总了Python中Tkinter.Tk.after方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.after方法的具体用法?Python Tk.after怎么用?Python Tk.after使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Tk
的用法示例。
在下文中一共展示了Tk.after方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class App(object):
def __init__(self, update, fps=8):
self.t = 0
self.period = 1000/fps
self.update = update
self.master = Tk()
m = self.update(self.t)
self.W, self.H = m3d.shape(m)
self.img = PhotoImage(width=self.W, height=self.H)
canvas = Canvas(self.master, width=self.W, height=self.H)
canvas.pack()
canvas.create_image((self.W/2, self.H/2), image=self.img, state="normal")
self._on_tick()
def _on_tick(self):
def _formatcolor(c):
return '#{0:02X}{1:02X}{2:02X}'.format(*c)
m = self.update(self.t)
self.img.blank()
lines = []
for j in xrange(self.H):
line = ' '.join(_formatcolor(m[j][i]) for i in xrange(self.W))
lines.append( '{' + line + '}')
self.img.put(' '.join(lines))
self.master.after(self.period, self._on_tick)
self.t += self.period
def start(self):
self.master.mainloop()
示例2: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def main():
root = Tk()
# w, h = root.winfo_screenwidth(), root.winfo_screenheight()
w, h = 960, 540
# get value from arduino
# ser = serial.Serial('/dev/tty.usbserial', 9600)
pos = 0
root.overrideredirect(1)
root.focus_set()
root.bind("<Escape>", lambda e: e.widget.quit())
root.geometry("%dx%d+300+300" % (w, h))
canvas = Canvas(root, width=w, height=h, background="black")
rect0 = canvas.create_rectangle(w/2-75, h/2-20, w/2+75, h/2+20, fill="#05f", outline="#05f")
rect1 = canvas.create_rectangle(w/2-20, h/2-75, w/2+20, h/2+75, fill="#05f", outline="#05f")
canvas.pack()
while (True):
# gets angle and moves accordingly
# pos = ser.readline()
canvas.move(rect0, 1, 0)
canvas.move(rect1, 1, 0)
root.update()
root.after(30)
app = App(root)
time.sleep(0.5)
root.mainloop()
示例3: success
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def success(cur_dir):
"""
Displays a "successful submission" picture
"""
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
img = Image.open(str(cur_dir) + '/Images/Success.gif')
width = img.size[0]
height = img.size[1]
flog = (root.winfo_screenwidth()/2-width/2)
blog = (root.winfo_screenheight()/2-height/2)
root.overrideredirect(1)
root.geometry('%dx%d+%d+%d' % (width, height, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
success_canvas = Canvas(root)
success_canvas.pack(fill = "both", expand = True)
# Open the image
imgtk = PhotoImage(img)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
success_canvas.create_image(cwidth/2, cheight/2, image = imgtk)
root.after(4000, root.destroy)
root.mainloop()
示例4: show
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def show(text, background="#fff", timeout_ms=DEFAULT_TIMEOUT, font_size=100):
root = Tk()
root.attributes("-topmost", True)
root.lift()
# Set Timeout
root.after(timeout_ms, root.destroy)
# Create Frame
frame = Frame(root)
frame.pack(side=TOP, fill=BOTH, expand=YES)
# Set frame size and position
screen_width = frame.master.winfo_screenwidth()
screen_heigh = frame.master.winfo_screenheight()
w = screen_width * 0.8
h = screen_heigh * 0.6
# Center the window
x = (screen_width/2) - (w/2)
y = (screen_heigh/2) - (h/2)
frame.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
# Adjust frame properties
frame.master.overrideredirect(True) # Set no border or title
frame.config(bg=background)
# Create text label
label = Label(frame, text=text, wraplength=screen_width * 0.8)
label.pack(side=TOP, expand=YES)
label.config(bg=background, justify=CENTER, font=("calibri", font_size))
# Set transparency
root.wait_visibility(root) # Needed for linux (and must come after overrideredirect)
root.attributes('-alpha', 0.6)
# Run Event loop
root.mainloop()
示例5: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def __init__(self, _text):
root = Tk()
root.title("Steep Hound alert")
label = Label(root, text=_text)
label.pack(ipadx=5, ipady=5, padx=5, pady=5)
root.after(5000, root.destroy)
root.mainloop()
示例6: failure
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def failure(reason, cur_dir):
"""
Displays a "submission failure" picture and emails
a bug report to maintenance.
"""
bugmail = {"email": "[email protected]"}
send_email(bugmail, "QR Code Submission Failure", reason, None)
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
gif = Image.open(str(cur_dir) + '/Images/Failure.gif')
width = gif.size[0]
height = gif.size[1]
flog = (root.winfo_screenwidth()/2-width/2)
blog = (root.winfo_screenheight()/2-height/2)
root.overrideredirect(1)
root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
failure_canvas = Canvas(root)
failure_canvas.pack(fill = "both", expand = True)
# Open the image
imgtk = PhotoImage(gif)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
failure_canvas.create_image(cwidth/2, cheight/2.24, image=imgtk)
Button(root, text = str(
reason), width = 50, height = 2, command = root.destroy).pack()
root.after(5000, root.destroy)
root.mainloop()
示例7: expired
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def expired(cur_dir, amount):
"""
Displays a "deadline expired" picture
"""
root = Tk()
root.focus_set()
# Get the size of the screen and place the splash screen in the center
img = Image.open(str(cur_dir) + '/Images/Expired.gif')
width = img.size[0]
height = img.size[1]
flog = root.winfo_screenwidth()/2-width/2
blog = root.winfo_screenheight()/2-height/2
root.overrideredirect(True)
root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
# Pack a canvas into the top level window.
# This will be used to place the image
expired_canvas = Canvas(root)
expired_canvas.pack(fill="both", expand=True)
# Open the image
imgtk = PhotoImage(img)
# Get the top level window size
# Need a call to update first, or else size is wrong
root.update()
cwidth = root.winfo_width()
cheight = root.winfo_height()
# create the image on the canvas
expired_canvas.create_image(cwidth/2, cheight/2.1, image=imgtk)
Button(root, text='Deadline Expired by ' + str(amount
) + '. Assignment Submitted, time '\
'noted', width=80, height=2, command=root.destroy).pack()
root.after(5000, root.destroy)
root.mainloop()
示例8: alert
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def alert(title, message):
box = Tk()
box.title(title)
Message(box, text = message, bg='red', fg = 'ivory').pack(padx=1, pady=1)
Button(box, text = "Close", command=box.destroy).pack(side=BOTTOM)
box.geometry('300x150')
box.after(0, hello)
示例9: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def main():
global game, master, window, IAs
#global game, IAs, actual_it
IAs = [Border, Learner, Chaser, Killer]
game = Game(800, 800, IAs)
master = Tk()
window = Canvas(master, width=game.width, height=game.height)
window.pack()
master.after(1, step)
master.mainloop()
示例10: TkMonitor
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class TkMonitor(Monitor):
"""
An interface over a dictionary {taskno: scrolledtext widget}, with
methods add_listener, del_listener, notify_listener and start/stop.
"""
def __init__(self, name, queue=None):
Monitor.__init__(self, name, queue)
self.widgets = {}
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def add_listener(self, taskno):
"There is a ScrolledText for each task"
st = ScrolledText(self.root, height=5)
st.insert('end', 'Output of task %d\n' % taskno)
st.pack()
self.widgets[taskno] = st
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def del_listener(self, taskno):
del self.widgets[taskno]
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def notify_listener(self, taskno, msg):
w = self.widgets[taskno]
w.insert('end', msg + '\n')
w.update()
def start(self):
'Start the mainloop'
self.root = Tk()
self.root.title(self.name)
self.root.wm_protocol("WM_DELETE_WINDOW", self.stop)
self.root.after(0, self.read_queue)
try:
self.root.mainloop()
except KeyboardInterrupt:
print >> sys.stderr, 'Process %d killed by CTRL-C' % os.getpid()
except TerminatedProcess:
pass
def stop(self):
self.root.quit()
def read_queue(self):
try:
cmd_args = self.queue.get_nowait()
except Queue.Empty:
pass
else:
getattr(self, cmd_args[0])(*cmd_args[1:])
self.root.after(100, self.read_queue)
示例11: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class Display:
def __init__(self, fps=FPS, width=WIDTH, height=HEIGHT,
board_offset_bottom=BOARD_OFFSET_BOTTOM,
board_width=BOARD_WIDTH,
board_height=BOARD_HEIGHT):
self.root=Tk()
self.root.protocol("WM_DELETE_WINDOW", self.root.destroy)
self.width = width
self.height = height
self.canvas=Canvas(self.root, bg="black",width=width,height=height)
self.board_width = board_width
self.board_height = board_height
self.board_offset_bottom = board_offset_bottom
self.canvas.pack()
self.fps = fps
self.controllers = []
#For reset
self.root.bind("<space>", lambda e:self.reset_all())
self.root.bind("<Escape>", lambda e:self.root.destroy())
def run(self):
self.root.after(1000//self.fps, self.loop)
try:
self.root.mainloop()
except KeyboardInterrupt:
self.root.destroy()
def loop(self):
actions = [controller.get_action(self.model) for controller in self.controllers]
self.model.update(1./self.fps, actions)
self.draw()
self.root.after(1000//self.fps, self.loop)
def draw(self):
self.canvas.delete('all')
self.board = self.canvas.create_rectangle(
self.model.x()-self.board_width/2,
self.board_offset_bottom+self.height-self.board_height,
self.model.x()+self.board_width/2,
self.board_offset_bottom+self.height, fill="green")
self.pendulum = self.canvas.create_line(
self.model.x(),
self.board_offset_bottom+self.height-self.board_height,
self.model.x()+self.model.arm_length*math.sin(self.model.alpha()),
self.board_offset_bottom+self.height-self.board_height-self.model.arm_length*math.cos(self.model.alpha()),
fill="blue", width=20)
def attach_model(self, model):
self.model = model
self.draw()
def attach_controller(self, controller):
self.controllers.append(controller)
def reset_all(self):
self.model.randomize()
示例12: GUI
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class GUI():
def __init__(self):
self.root = Tk()
self.show()
def show(self):
self.root.deiconify()
#self.root.attributes('-topmost', 1)
#self.root.attributes('-topmost', 0)
self.root.after(2000, self.hide)
def hide(self):
self.root.iconify()
self.root.after(2000, self.show)
示例13: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class gui:
def __init__(self):
self.tk = Tk()
self.canvas = Canvas(self.tk)
self.tk.after_idle(self.test)
self.tk.mainloop()
def test(self):
print 'boom'
self.tk.after(200, self.test2)
def test2(self):
print 'bang'
self.tk.after(200, self.test)
示例14: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
def main():
root = Tk()
def kludge():
root.after(100, kludge)
root.after(100, kludge)
def handle_sigusr1(signum, frame):
root.quit()
signal.signal(signal.SIGUSR1, handle_sigusr1)
root.geometry("250x150+300+300")
root.attributes("-fullscreen", True)
app = Example(root)
root.mainloop()
print("Here we are cleaning up.")
示例15: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import after [as 别名]
class GUI:
def __init__(self, num_labels):
self.root = Tk()
self.labels = []
for i in xrange(num_labels):
l=Label(self.root, width=10, height=5)
l.grid(row=0, column=i)
self.labels.append(l)
def color(self, i, value):
self.labels[i].configure(bg=value)
def mainloop(self):
self.root.mainloop()
def delay_color(self, delay, i, color):
self.root.after(delay, lambda: self.color(i, value))
def after(self, delay, cb):
self.root.after(delay, cb)