本文整理汇总了Python中tkinter.Tk.update方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.update方法的具体用法?Python Tk.update怎么用?Python Tk.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Tk
的用法示例。
在下文中一共展示了Tk.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
def main():
root = Tk()
root.title("Paddle Game")
root.resizable(0, 0)
root.wm_attributes("-topmost", 1)
canvas = Canvas(root, width=500, height=400, bd=0, highlightthickness=0)
canvas.pack()
root.update()
paddle = Paddle(canvas, "blue")
ball = Ball(canvas, paddle, "red")
while True:
if not ball.hit_bottom:
ball.draw()
paddle.draw()
root.update_idletasks()
root.update()
time.sleep(0.01)
示例2: Wall
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
class Wall(object):
MIN_RED = MIN_GREEN = MIN_BLUE = 0x0
MAX_RED = MAX_GREEN = MAX_BLUE = 0xFF
PIXEL_WIDTH = 50
def __init__(self, width, height):
self.width = width
self.height = height
self._tk_init()
self.pixels = [(0, 0, 0) for i in range(self.width * self.height)]
def _tk_init(self):
self.root = Tk()
self.root.title("ColorWall %d x %d" % (self.width, self.height))
self.root.resizable(0, 0)
self.frame = Frame(self.root, bd=5, relief=SUNKEN)
self.frame.pack()
self.canvas = Canvas(self.frame,
width=self.PIXEL_WIDTH * self.width,
height=self.PIXEL_WIDTH * self.height,
bd=0, highlightthickness=0)
self.canvas.pack()
self.root.update()
def set_pixel(self, x, y, hsv):
self.pixels[self.width * y + x] = hsv
def get_pixel(self, x, y):
return self.pixels[self.width * y + x]
def draw(self):
self.canvas.delete(ALL)
for x in range(len(self.pixels)):
x_0 = (x % self.width) * self.PIXEL_WIDTH
y_0 = (x / self.width) * self.PIXEL_WIDTH
x_1 = x_0 + self.PIXEL_WIDTH
y_1 = y_0 + self.PIXEL_WIDTH
hue = "#%02x%02x%02x" % self._get_rgb(self.pixels[x])
self.canvas.create_rectangle(x_0, y_0, x_1, y_1, fill=hue)
self.canvas.update()
def clear(self):
for i in range(self.width * self.height):
self.pixels[i] = (0, 0, 0)
def _hsv_to_rgb(self, hsv):
rgb = colorsys.hsv_to_rgb(*hsv)
red = self.MAX_RED * rgb[0]
green = self.MAX_GREEN * rgb[1]
blue = self.MAX_BLUE * rgb[2]
return (red, green, blue)
def _get_rgb(self, hsv):
red, green, blue = self._hsv_to_rgb(hsv)
red = int(float(red) / (self.MAX_RED - self.MIN_RED) * 0xFF)
green = int(float(green) / (self.MAX_GREEN - self.MIN_GREEN) * 0xFF)
blue = int(float(blue) / (self.MAX_BLUE - self.MIN_BLUE) * 0xFF)
return (red, green, blue)
示例3: rdyOpen
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
def rdyOpen():
root = Tk()
root.withdraw()
root.update()
filePath = askopenfilename(initialdir = "", filetypes = (("RDY Files", "*.rdy"),("All Files","*.RDY")),title = "Choose a new RDY File")
root.destroy()
return filePath
示例4: dirOpen
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
def dirOpen():
root = Tk()
root.withdraw()
root.update()
filePath = askdirectory(initialdir = "", title = "Choose the RDY folder destination")
root.destroy()
return filePath
示例5: priorityOpen
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
def priorityOpen():
root = Tk()
root.withdraw()
root.update()
filePath = askopenfilename(initialdir = "", filetypes = (("Excel Files", "*.xls"),("Excel Files","*.xlsx")),title = "Choose a new Priority Excel File")
root.destroy()
return filePath
示例6: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
class GUI:
def __init__(self):
self.app = Tk()
self.app.title('TicTacToe')
self.app.resizable(width=False, height=False)
self.board = Board()
self.font = Font(family="Helvetica", size=32)
self.buttons = {}
for x,y in self.board.fields:
handler = lambda x=x,y=y: self.move(x,y)
button = Button(self.app, command=handler, font=self.font, width=2, height=1)
button.grid(row=y, column=x)
self.buttons[x,y] = button
handler = lambda: self.reset()
button = Button(self.app, text='reset', command=handler)
button.grid(row=self.board.size+1, column=0, columnspan=self.board.size, sticky="WE")
self.update()
def reset(self):
self.board = Board()
self.update()
def move(self,x,y):
self.app.config(cursor="watch")
self.app.update()
self.board = self.board.move(x,y)
self.update()
move = self.board.best()
if move:
self.board = self.board.move(*move)
self.update()
self.app.config(cursor="")
def update(self):
for (x,y) in self.board.fields:
text = self.board.fields[x,y]
self.buttons[x,y]['text'] = text
self.buttons[x,y]['disabledforeground'] = 'black'
if text==self.board.empty:
self.buttons[x,y]['state'] = 'normal'
else:
self.buttons[x,y]['state'] = 'disabled'
winning = self.board.won()
if winning:
for x,y in winning:
self.buttons[x,y]['disabledforeground'] = 'red'
for x,y in self.buttons:
self.buttons[x,y]['state'] = 'disabled'
for (x,y) in self.board.fields:
self.buttons[x,y].update()
def mainloop(self):
self.app.mainloop()
示例7: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
class AppEventLoop:
""" An event loop
tk specific application event loop
"""
def __init__(self, app=None):
if app is None:
self.app = Tk()
self.outputs = []
self.events = curio.UniversalQueue()
self.app.bind('<Key>', self.keypress)
def set_event_queue(self, events):
self.events = events
def keypress(self, event):
""" Take tk events and stick them in a curio queue """
self.events.put(event.char)
return True
async def flush(self):
""" Wait for an event to arrive in the queue.
"""
while True:
event = await self.queue.get()
self.app.update_idletasks()
self.app.update()
async def poll(self):
# Experiment with sleep to keep gui responsive
# but not a cpu hog.
event = 0
nap = 0.05
while True:
# FIXME - have Qt do the put when it wants refreshing
await self.put(event)
event += 1
nap = await self.naptime(nap)
# FIXME should do away with the poll loop and just schedule
# for some time in the future.
await curio.sleep(nap)
async def naptime(self, naptime=None):
""" Return the time to nap
FIXME: make this adaptive, but keep it responsive
The idea would be to see how many events each poll produces.
So, if there are a lot of events, shorten the naps.
If there are not so many take a longer nap
This should take into account how fast events are taking to arrive and
how long they are taking to process and balance the two.
And don't sleep too long, in case some other task wakes up and starts talking.
Better still, might be to have something else managing nap times.
For now, keep it simple.
"""
if naptime is None:
nap = 0.05
return naptime
示例8: format
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
r>>=4+1#reduce the intensity
g>>=4+1
b>>=4+1
if (r,g,b)!=(0,0,0):
fichier.write("\tdrawPixel2({},{},{},{},{},offset);\n".
format(x,y,r,g,b) )
fichier.write("}\n")
if(self.AnimationVar.get()):
fichier.write("#define ANIMATION\n")
def upload(self):
self.write_matrix(RESULT_PATH)
os.system("make upload")
if __name__=="__main__":
root = Tk()
root.withdraw()
my_gui = kaleidoGui(root)
if len(argv)>1:
my_gui.import_image(argv[1])
my_gui.upload()
exit(0)
root.update()
root.deiconify()
root.mainloop()
示例9: Tk
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
from tkinter import Tk, Canvas, PhotoImage
import time
import numpy as np
tk = Tk()
canvas = Canvas(tk, width=1000, height=1000)
canvasicon = Canvas(tk, width=300, height=300)
canvaslogo = Canvas(tk, width=300, height=300)
canvasstat = Canvas(tk, width=300, height=300)
canvas.grid(column=0, row=0)
canvasicon.grid(column=1, row=0)
canvaslogo.place(x=1000, y=0)
canvasstat.place(x=1000, y=700)
tk.update_idletasks()
tk.update()
contact_bool = False
launch_bool = False
body_landed = None
dist_body_landed = None
closest_body = None
crash = False
center_shiftx = 0
center_shifty = 0
total_shiftx = 0
total_shifty = 0
contact_number = 0
gravity_constant = 6.67384 * (10**-11)
orbital_velocity_text = canvasstat.create_text(155, 100, text=None, font=('Courier', 10))
velocity_text = canvasstat.create_text(80, 150, text=None, font=('Courier', 10))
name_text = canvasstat.create_text(97, 50, text=None, font=('Courier', 10))
logo = PhotoImage(file='logo.gif')
示例10: Tk
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
s = serial.Serial(serial_port, serial_baudrate)
# Initialize camera
cam = cv2.VideoCapture(0)
# Find the dimensions of the picture
pic = cam.read()[1]
camheight, camwidth, l = pic.shape
framewidth = camwidth//3
# Initialize plot
if showPlot:
plt.ion()
plt.show()
i = 0
if multiple_sessions:
window = Tk()
window.withdraw()
window.update()
csvname = askopenfilename()
# Pull values from .csv file
vals = []
with open(csvname) as csvfile:
rdr = csv.reader(csvfile)
i = 0
for row in rdr:
vals.append([])
vals[i].append(row[0]) # add the name as a string
j = 1
while j < len(row):
vals[i].append(float(row[j])) # everything else is a number
j += 1
i += 1
# Create sessions from values
示例11: main
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
def main():
r = Tk()
#r.withdraw()
r.clipboard_clear()
r.clipboard_append(get_random_ik())
r.update()
示例12: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
class TTTGui:
def __init__(self, controller, dimension):
self.controller = controller
self.root = Tk() # put this here removes Tkinter dep in the Controller
self.root.title('TicTacToe Minimax')
self.root.resizable(width=False, height=False)
self.font = Font(family="Helvetica", size=128)
self.buttons = {}
self.dimension = dimension
self.draw_grids()
self.load_restart_button()
def draw_grids(self):
for x in range (0, self.dimension):
for y in range(0, self.dimension):
handler = lambda x=x,y=y: self.playerMoved(x, y)
button = Button(self.root, command=handler, font=self.font, width=2, height=1)
button.grid(row=x, column=y)
self.buttons[x,y] = button
def load_restart_button(self):
button = Button(self.root, text='Restart',font=Font(family="Helvetica", size=32), command=lambda: self.controller.restart(self.reloadUI))
button.grid(row=self.dimension + 1, column=0, columnspan=self.dimension, sticky="WE")
self.root.update()
def updateUI(self, board_state, winCoordinates=None):
# winCoordinates is a list of the winning coordinates
for x in range(len(board_state)):
for y in range(len(board_state[0])):
if board_state[x][y] != 0:
self.buttons[x, y]['disabledforeground'] = 'black'
self.buttons[x, y]['state'] = 'disabled'
self.buttons[x, y]['relief'] = 'sunken'
if board_state[x][y] == 'x':
self.buttons[x, y]['text'] = 'x'
if board_state[x][y] == 'o':
self.buttons[x, y]['text'] = 'o'
if winCoordinates is not None:
for x, y in winCoordinates:
self.buttons[x, y]['disabledforeground'] = 'red'
for x in range(len(board_state)):
for y in range(len(board_state[0])):
self.buttons[x, y]['relief'] = 'sunken'
self.buttons[x, y]['state'] = 'disabled'
def reloadUI(self, board_state):
print("Restarting Game.")
for x in range(len(board_state)):
for y in range(len(board_state[0])):
self.buttons[x, y]['relief'] = 'raised'
self.buttons[x, y]['state'] = 'normal'
self.buttons[x, y]['text'] = ""
self.updateUI(board_state)
def playerMoved(self, x, y):
print('Played Moved: ', x,y)
self.controller.updateModel(x, y, self.updateUI)
def start(self, state):
self.updateUI(state)
self.root.mainloop()
示例13: Tk
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
return self.right()
self.canvas.move(self.id, -self.vecx, self.vecy)
return self.left
root = Tk()
root.title("Blobs")
root.resizable(0, 0)
frame = Frame(root, bd=10, relief=SUNKEN)
frame.pack()
canvas = Canvas(frame, width=500, height=300, bd=0, highlightthickness=0)
canvas.pack()
speed = 0.0003
dy = 1
items = [
Ball(canvas, (0, 10), "red", 0.101, 0.020)
]
root.update() # fix geometry
# loop over items
try:
while 1:
for i in range(len(items)):
items[i] = items[i]()
root.update_idletasks() # redraw
time.sleep(.001)
root.update() # process events
except RuntimeError:
pass # to avoid errors when the window is closed
示例14: __init__
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
class Gem:
def __init__(self):
self.frame = Tk();
self.frame.resizable(False, False)
self.status = 1
self.scorePlayerA = 0
self.scorePlayerB = 0
self.scoreRoundA = 0
self.scoreRoundB = 0
self.countRound = 0
self.quitMatch = 0
self.isQuitRound = 0
self.canvas_after_2 = 0
self.canvas_after_1 = 0
self.isPause = 0
#register event
self.frame.bind("<F4>", self.quitGame)
self.frame.bind("<F5>", self.pauseGame)
self.frame.protocol("WM_DELETE_WINDOW", self.on_closing)
self.registerKeyboard()
def setName(self, title):
self.frame.title(title)
def setBall(self, ball):
self.ball = ball
def setLeftBar(self, bar):
self.leftBar = bar
def setRightBar(self, bar):
self.rightBar = bar
def run(self):
self.frame.mainloop()
def getFrame(self):
return self.frame;
def getCanvas(self):
return self.canvas
def setSize(self, size):
self.frame.geometry(("%dx%d")%(size[0], size[1]))
self.frame.update()
def getSize(self):
return (self.frame.winfo_width(), self.frame.winfo_height())
def setBackground(self, color):
self.background = color
def setPlayers(self, players):
self.players = players
def setScoreBoard(self):
players = self.players
size = self.getSize()
mid = round(size[0]/2)
# Board
self.canvas.create_rectangle(mid - 100, 0, mid + 100, 35, fill="grey58", outline="white", tag="boarda")
# Player name 1
self.canvas.create_text(mid - 80, 15, text=players[0], fill="magenta2", tag="boardb")
# Round score 1
r1 = players[0]+"a"
self.canvas.create_text(mid - 80, 28, text="0", fill="pale green", tag="scoreplayera")
# Player name 2
self.canvas.create_text(mid + 80, 15, text=players[1], fill="magenta2", tag="boardc")
# Round score 2
self.canvas.create_text(mid + 80, 28, text="0", fill="pale green", tag="scoreplayerb")
# Box score 1
self.canvas.create_rectangle(mid - 50, 5, mid - 10, 25, fill="thistle3", outline="white", tag="boardd")
# Score 1
self.canvas.create_text(mid - 30, 15, text="000", fill="cyan", tag=players[0])
# Box score 2
self.canvas.create_rectangle(mid + 10, 5, mid + 50, 25, fill="thistle3", outline="white", tag="boarde")
# Score 2
self.canvas.create_text(mid + 30, 15, text="000", fill="cyan", tag=players[1])
self.canvas.pack()
self.frame.update()
def clearScoreBoard(self):
self.canvas.delete(self.players[0])
self.canvas.delete(self.players[1])
self.canvas.delete("boarda")
#.........这里部分代码省略.........
示例15: print
# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import update [as 别名]
liste2=np.empty_like(liste)
fen1=Tk()
cadrillage=Canvas(fen1, bg='light grey', height=640, width=640)
cadrillage.pack()
fen1.quit()
fen1
i=0
k=0
while True:
try:
humain=liste[i]
x=humain[0][0]*20
y=humain[0][1]*20
cadrillage.create_rectangle(x,y,x+20,y+20, fill="red", outline="black")
fen1.update()
except:
print()
k+=1
if k>20:
fen1.destroy()
exit()
addVoisin()
#t.sleep(0.001)
i+=1
fen1.mainloop()