tkinter-canvas

Saving canvas from tkinter to file

…衆ロ難τιáo~ 提交于 2020-03-27 19:49:09
问题 So I followed this post: How can I convert canvas content to an image? And when I tried to do as mentioned in the last suggestion, I get the following problem: When I call it out like this, the image/screenshot is taken too early and therefore the required image won't be captured. Here's the code: from tkinter import * from PIL import ImageGrab root = Tk() cv = Canvas(root) cv.pack() cv.create_rectangle(10,10,50,50) #cv.create_line([0, 10, 10, 10], fill='green') cv.update() #print(root.winfo

tkinter bouncing ball

社会主义新天地 提交于 2020-02-25 05:25:49
问题 I am currently studying computer science in university doing a foundation year, so I'm new to programming, we are doing a python unit and I'm doing my own project outside of the course content. I've been trying to make a bouncing ball animation using Tkinter. However I have two balls, red and green, for some reason they don't seem to touch the top or left side of the canvas before the bouncing, and the distance from the edge seems to constantly increase. from tkinter import * import random

Numpy Matrix to tkinter Canvas

时光怂恿深爱的人放手 提交于 2020-01-23 03:17:33
问题 How to display a Numpy matrix, as a bitmap, into a Tkinter canvas? More precisely, how to fill a PhotoImage with content from a matrix? photo = ImageTk.PhotoImage(...) self.canvas.create_image(0,0,image=photo,anchor=Tkinter.NW) 回答1: Here is working solution, slightly modified to make it work (some function was deprecated) and to simplify it to keep only the necessary part. We have to use Image.frombytes(...) to read the data in the numpy matrix. import Tkinter from PIL import Image, ImageTk

How do I create a pentagon and hexagon using create_line in python tkinter canvas?

大兔子大兔子 提交于 2020-01-17 14:47:05
问题 Here is the code I have for drawing a triangle and square in python tkinter canvas using create_lines, how would I use create_lines to create a pentagon and hexagon? Note: For the pentagon and hexagon, the length and width refer to the total square shaped area the shape is contained within, not the width and length of the sides. self.x, self.y = 50, 50 def triangle(self): width = self.width.get() length = self.length.get() color = self.color_select.get() self.canvas.create_line(self.x, self.y

Have after() method run on time Tkinter

跟風遠走 提交于 2020-01-17 07:59:08
问题 I'm programming a tool that has to display a timer with 1/100 of second as precision in Tkinter with python. I've tried using the after() method with self.timerLabel.after(0, self.update_timer) def update_timer (self): self.timer += 0.01 self.timerLabel.configure(text="%.2f" % self.timer) self.timerLabel.after(10, self.update_timer) The problem is that it runs way slower than expected and I need to know if there's a workaround or some way to have the timer run exactly on time. Or maybe some

How to speed up tkinter embedded matplot lib and python

你。 提交于 2020-01-17 06:53:26
问题 I have a GUI that I am using to send a query data from an arduino. I then went to live graph this data without slow down. I currently am getting slow down with the more numbers that I am plotting and i had a similar problem when I first wrote this GUI in matlab. I wanted to know if i could make this faster as I eventually want to be able to graph to multiple windows at once. I am aware of the animation library from a previous suggestion but was unsuccessful with getting it to work insife of

How to speed up tkinter embedded matplot lib and python

≯℡__Kan透↙ 提交于 2020-01-17 06:53:23
问题 I have a GUI that I am using to send a query data from an arduino. I then went to live graph this data without slow down. I currently am getting slow down with the more numbers that I am plotting and i had a similar problem when I first wrote this GUI in matlab. I wanted to know if i could make this faster as I eventually want to be able to graph to multiple windows at once. I am aware of the animation library from a previous suggestion but was unsuccessful with getting it to work insife of

How to update a plot on Tkinter canvas?

拥有回忆 提交于 2020-01-14 02:37:08
问题 I have a tkinter app where I have different frames, each one with a different plot. I have an import function that allows me to select the data file that I want to plot. Right now, everything is working well if I import the file right at the start of the program, i.e. as soon as the subplot is created on the canvas the data is shown. However, if the subplot is created beforehand without any data, when I import the data and call the function to plot it, the canvas does not update the plot. BUT

Python Tkinter save canvas as image using PIL

北城以北 提交于 2020-01-13 11:49:06
问题 I have this code which lets the user draw on the canvas and save it as a jpeg file. As mentioned in this post, I tried to draw in parallel on the canvas and in memory using the PIL so that I can save it as a jpeg instead of postscript . It seemed to be working until I found out that some of the images I saved with PIL are not the same as what was drawn on the canvas. I assume canvas.create_line and draw.line from the PIL image draw module function similarly and should give similar output.

Remove automatic gap between gridded python Tkinter widgets

北慕城南 提交于 2020-01-11 12:50:29
问题 I'm using python2 on Windows. When I run the followig code, I get a gap between the two canvas (see picture below), although there is no padding specified when I grid them. Is there any possibility to remove this? import Tkinter as tk import ttk class App(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.c1 = tk.Canvas(master=self, background='white', borderwidth=0, relief=tk.FLAT) self.c2 = tk.Canvas(master=self, background='white', borderwidth=0, relief