tkinter-canvas

Python tkinter canvas transparent

﹥>﹥吖頭↗ 提交于 2019-12-07 01:01:34
I am looking to make the background of the tkinter canvas transparent, but still have Mouse events of the canvas, here is my code, I am on Windows 10, Python 3.6: from tkinter import * import time WIDTH = 500 HEIGHT = 500 LINEWIDTH = 1 TRANSCOLOUR = 'gray' global old old = () tk = Tk() tk.title('Virtual whiteboard') tk.wm_attributes('-transparentcolor', TRANSCOLOUR) canvas = Canvas(tk, width=WIDTH, height=HEIGHT) canvas.pack() canvas.config(cursor='tcross') canvas.create_rectangle(0, 0, WIDTH, HEIGHT, fill=TRANSCOLOUR, outline=TRANSCOLOUR) def buttonmotion(evt): global old if old == (): old =

Tkinter w.destroy() blocks/resets window resize

给你一囗甜甜゛ 提交于 2019-12-06 15:58:09
问题 I have a Python 3.5 app using tkinter and create/remove widgets in a canvas on the fly. I noticed that when a widget is being destroyed using w.destroy() during the callback of a window resize, the callback finished correctly, but the window is being reset to its original size. I've tried to delay the w.destroy() using self.after(1000, self.resize) and that kind off works but when dragging/holding the cursor down while the callback is being fired, the resize jumps back anyway. Anyone having a

NagivationToolbar fails when updating in Tkinter canvas

北慕城南 提交于 2019-12-06 11:29:11
问题 I am trying to update a two-panel plot in Tkinter canvas using matplotlib. Here is the minimum code that shows my current understanding. The main problem is while the navigation toolbar works for the initial plots (y = sin(x), y = cos(x)), however it fails when I press the update button to update it. For example if I zoom in a curve, I cannot use home button to return to its original state. I have been trying different ways, but to no avail. I would appreciate anyone's suggestions. One minor

Converting PostScript to an image [closed]

牧云@^-^@ 提交于 2019-12-06 09:22:01
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm having trouble converting a postscript (.eps) file to any kind of image. Whenever I use PIL to save the loaded .eps file the quality of it is horrible and text rendered in tkinter is unreadable. I think this is because the .eps file is some sort of vector image and saving it using PIL doesn't render the correct resolution but I'm not sure. Does anyone know how I could either save a PostScript file at a

Python Tkinter save canvas as image using PIL

给你一囗甜甜゛ 提交于 2019-12-05 18:42:52
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. Below is what went wrong: For example, when I draw a "T" it seems alright (Left is my drawing, right is

Tkinter w.destroy() blocks/resets window resize

余生长醉 提交于 2019-12-04 21:49:40
I have a Python 3.5 app using tkinter and create/remove widgets in a canvas on the fly. I noticed that when a widget is being destroyed using w.destroy() during the callback of a window resize, the callback finished correctly, but the window is being reset to its original size. I've tried to delay the w.destroy() using self.after(1000, self.resize) and that kind off works but when dragging/holding the cursor down while the callback is being fired, the resize jumps back anyway. Anyone having a suggestion to remove widgets on the fly and release memory? UPDATE: As a workaround I mark widgets to

NagivationToolbar fails when updating in Tkinter canvas

随声附和 提交于 2019-12-04 15:26:59
I am trying to update a two-panel plot in Tkinter canvas using matplotlib. Here is the minimum code that shows my current understanding. The main problem is while the navigation toolbar works for the initial plots (y = sin(x), y = cos(x)), however it fails when I press the update button to update it. For example if I zoom in a curve, I cannot use home button to return to its original state. I have been trying different ways, but to no avail. I would appreciate anyone's suggestions. One minor issue I notice is that if I want to kill the plot, I should go to menubar and select python/quit Python

Tkinter understanding after()

谁说我不能喝 提交于 2019-12-04 10:54:18
First of all, take a look at my previous thread here: Tkinter understanding mainloop After following the advice from there, in GUI programming, infinite loops have to be avoided at all costs, in order to keep the widgets responsive to user input. Instead of using: while 1: ball.draw() root.update() time.sleep(0.01) I managed using self.canvas.after(1, self.draw) inside my draw() function. So my code now looks like this: # Testing skills in game programming from Tkinter import * root = Tk() root.title("Python game testing") root.resizable(0, 0) root.wm_attributes("-topmost", 1) canvas = Canvas

Python Tkinter Scrollable Frame Class?

被刻印的时光 ゝ 提交于 2019-12-04 04:59:18
问题 I would like to make a Tkinter class , based on the answer here, which is a Frame that automatically shows/hides Scrollbar s around the content as necessary. The answer that I linked to above works perfectly for my needs, with the caveat that because it's not contained within a class , it's not reusable. I figured this would be pretty quick and easy, but for some reason, my AutoScrollbar s never appear once I refactor the code into its own class , regardless of how much or little of the

How to open PIL Image in Tkinter on Canvas

限于喜欢 提交于 2019-12-04 03:36:39
I can't seem to get my PIL Image to work on canvas. Code: from Tkinter import* import Image, ImageTk root = Tk() root.geometry('1000x1000') canvas = Canvas(root,width=999,height=999) canvas.pack() image = ImageTk.PhotoImage("ball.gif") imagesprite = canvas.create_image(400,400,image=image) root.mainloop() Error: Traceback (most recent call last): File "C:/Users/Mark Malkin/Desktop/3d Graphics Testing/afdds.py", line 7, in <module> image = ImageTk.PhotoImage("ball.gif") File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 109, in __init__ mode = Image.getmodebase(mode) File "C:\Python27