tkinter-canvas

Sort Algorithm Visualization: How to pull values to animate the canvas, from inside a tight loop

半城伤御伤魂 提交于 2019-12-13 02:54:14
问题 I am working on a visualization of different sorting algorithms using the height of different bars with tkinter. I have been able to shuffle the bars and also sort them after some help. The problem I am having now is slowing the sorting of the bars down so it can be seen how each algorithm works. Here is what I have so far: import tkinter as tk import random def swap_two_pos(pos_0, pos_1): Bar1x1, _, Bar1x2, _ = canvas.coords(pos_0) Bar2x1, _, Bar2x2, _ = canvas.coords(pos_1) canvas.move(pos

How to get Numpy array of Canvas data?

对着背影说爱祢 提交于 2019-12-13 02:37:12
问题 I am building an application with Tkinter, where one is able to draw e.g. lines in a Canvas. This works well. However, I'm unable to find a method for getting the current Canvas data. Preferably I would like to get a numpy array out of the current Canvas data, since my post-processing steps are mostly using numpy. Is there any way to build numpy arrays out of the Canvas data? In some color format like RGB, by preference? I know that I can get the information e.g. of lines (like coordinates)

python tkinter canvas not resizing

拟墨画扇 提交于 2019-12-13 01:13:37
问题 I'm trying to subclass some tkinter controls to make an auto scrolling frame for use in my program, i only want it to scroll vertically, and when widgets are added that need it to scroll horizontally instead to resize the parent to fit. widgets that go in this frame are not all defined at runtime and are created dynamically, so it must react to events. I have some code that is partly working, in that it i run it, i can use the buttons at the bottom to add and remove labels on the fly, if i do

How to rotate an image on a canvas without using PIL?

蓝咒 提交于 2019-12-12 23:34:28
问题 Is there any simple way to rotate an imported image on a tkinter canvas? I'd rather not use the PIL module, but I can't find any viable alternatives. (If it helps, I want to rotate some car images when they take a turn on a crossroad.) 回答1: Below is a simple but not efficient method to rotate a PhotoImage 90 (right), 180 and 270 (left) degrees: def rotate_image(img, dir): w, h = img.width(), img.height() if dir in ['left', 'right']: newimg = PhotoImage(width=h, height=w) else: # 180 degree

Cannot delete tkinter object on canvas

人盡茶涼 提交于 2019-12-12 22:51:25
问题 I have created a class object Dot() , a function update() that updates its position and then generated many instances of it on canvas , adding them to a list. I run a loop that keeps updating the position of the dots, and this works fine, but I also want to delete one instantiation of Dot() at each run of the loop. I've tried many ways but with no success. By using canvas.delete() function I only "freeze" the instantiation, but it remains on screen. How can I fix this? import numpy as np

tkinter Canvas window size

五迷三道 提交于 2019-12-12 16:02:56
问题 I need to know when the Canvas is resized (eg when the master frame gets maximized) the new Canvas window size. Unfortunately, if I try self.canvas['width'] it always seems to me I get back the width it had whenever I initialized it and not the current width. How do I get the current Canvas window dimensions? 回答1: When you retrieve self.canvas['width'] , you are asking tkinter to give you the configured width of the widget, not the actual width. For the actual width you can use .winfo_width()

Why does this shape in Tkinter update slowly?

做~自己de王妃 提交于 2019-12-12 10:46:49
问题 Attempted to do simple movement in tkinter: import tkinter as tk class GameApp(object): """ An object for the game window. Attributes: master: Main window tied to the application canvas: The canvas of this window """ def __init__(self, master): """ Initialize the window and canvas of the game. """ self.master = master self.master.title = "Game" self.master.geometry('{}x{}'.format(500, 500)) self.canvas = tk.Canvas(self.master) self.canvas.pack(side="top", fill="both", expand=True) self.start

cannot draw matplotlib chart in tkinter GUI without crashing

依然范特西╮ 提交于 2019-12-12 04:26:55
问题 I'm currently following this link with a tutorial: Here is the one I am following. The dude gives you the code. Have included it at the bottom anyway. Would definitely recommend. But now facing issues: Using Spyder 2.3.8 Python 3.5 Everything up to date Have set the backend for Spyder to read matplotlib as 'TkAgg' (also took ages!). Have hashtagged out the three lines which are causing the issue. Works fine when these lines aren't active. Activating them and running causes my terminal to

Filling a Tkinter Canvas Element with an Image

﹥>﹥吖頭↗ 提交于 2019-12-12 03:28:25
问题 Is there any way to fill a Tkinter element (more specifically an oval) with an image. If not, is there any way to resize an image to fit into an oval? I also would prefer not to use PIL. canvas.create_oval(val1, val2, val1+sz, val2+sz, fill=clr, outline=outln) How would you get an image to fit inside a circle like so? I would also certainly cull the edges around the image if you were wondering. 回答1: In plain Tkinter your options are limited. One thing you could do is create a 'mask' image

Canvas leaves scrollregion if scrolled with mouswheel

*爱你&永不变心* 提交于 2019-12-12 00:38:57
问题 Problem: you can scroll upwards even though the first item should be at the very top of the canvas How to reproduce the problem: have at least one item on the canvas and scroll using the mouse ( press space to make an item ) Note: the problem ceases once the items are wider than the canvas itself Sample code import tkinter as tk class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.bind("<MouseWheel>", self.scroll) self.bind("<KeyPress>", self.keypressed) self.TargetCanvas = None