tkinter-canvas

How to open PIL Image in Tkinter on Canvas

血红的双手。 提交于 2019-12-09 16:45:32
问题 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

Tkinter Canvas move item to top level

被刻印的时光 ゝ 提交于 2019-12-08 19:43:54
问题 I have a Tkinter Canvas widget (Python 2.7, not 3), and on this Canvas I have different items. If I create a new item that overlaps an old item, It will be in front. How can I now move the old item in front of the newly created one, or even in front of all other items on the Canvas? Example code so far: from Tkinter import * root = Tk() canvas = Canvas(root,width=200,height=200,bg="white") canvas.grid() firstRect = canvas.create_rectangle(0,0,10,10,fill="red") secondRect = canvas.create

How to convert Tkinter canvas coordinate to window?

霸气de小男生 提交于 2019-12-08 19:27:03
问题 Is there a way to convert canvas coordinates to window coordinates in Tkinter? It would be the opposite of converting from window to canvas coordinate, wich is done like this: x = canvas.canvasx(event.x) 回答1: Use the canvasx and canvasy methods, giving an argument of zero, to compute the x/y of the upper left corner of the visible canvas. Then just use math to convert the canvas coordinate to something relative to the window. # upper left corner of the visible region x0 = self.canvas.canvasx

IntVar returning only 0 even with .get() function

╄→尐↘猪︶ㄣ 提交于 2019-12-08 11:48:34
问题 This is a population model so the entries must be integers to be used for calculation. import sys import tkinter from tkinter import* import time global v global popJ popJ = 0 def genInput(): #Allows the user to input the data gen = Tk() gen.wm_title("Data Input") v = IntVar() ent1 = Entry(gen, textvariable = v).pack() ent1Txt = Label(gen, text = 'Input Juvenile Populations') ent1Txt.pack() v2 = StringVar() ent2 = Entry(gen, textvariable = v2) ent2Txt = Label(gen, text = 'Input Adult

Embedding matplotlib canvas into tkinter GUI - plot is not showing up, but no error is thrown

无人久伴 提交于 2019-12-08 11:19:18
问题 Running the python python script below does not show the embedded matplotlib plot. However it also throws no error message. Upon running the script, it is supposed to display a GUI displaying 4 buttons on the left hand side and a realtime graph on the right hand side. The graph receives its input from a text file 'sample_graph_data.txt' , which is in the same directory as the script. What's wrong in the script and how do I make it work? #Script begins here from tkinter import * from tkinter

How to draw a polygon on a tkinter canvas using a class?

瘦欲@ 提交于 2019-12-08 09:46:20
问题 from tkinter import* root = Tk() shape = Canvas(root) class GUI(): def __init__(self): pass def create_polygon(self, points, colour, posit): try: shape.delete(self.poly) except: pass self.poly = shape.create_polygon(points, colour, posit) self.poly.shape.grid(column=posit[0],row=posit[1]) polygon = GUI() polygon.create_polygon([150,75,225,0,300,75,225,150],'yellow',[1,2]) I'm new to using tkinter and classes but I want to make a very simple class to create a regular polygon. The code in this

Python tkinter canvas transparent

时光总嘲笑我的痴心妄想 提交于 2019-12-08 05:37:52
问题 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

Turtle freehand drawing

匆匆过客 提交于 2019-12-08 05:25:05
问题 I'm working on a simple drawing program that combines Tkinter and Turtle modules. I would like to add an option that the user can draw anything by just using mouse similar to pen widget on Paint. I tried many things, I could not figure out how l can do it.How can l make the turtle draw anything (like pen widget on Paint ) on canvas by using mouse from tkinter import * import turtle sc=Tk() sc.geometry("1000x1000+100+100") fr4=Frame(sc,height=500,width=600,bd=4,bg="light green",takefocus=""

Move object in python tkinter canvas

泪湿孤枕 提交于 2019-12-08 04:50:31
问题 so I have a submarine: from tkinter import * HEIGHT = 500 WIDTH = 800 window = Tk() window.title("Bubble Blaster") c = Canvas(window, width=WIDTH, height=HEIGHT, bg="darkblue") c.pack() ship_id = c.create_polygon(5, 5, 5, 25, 30, 15, fill="red") ship_id2 = c.create_oval(0, 0, 30, 30, outline="red") and Im reading a book on how to make the sub move, this is what it says: def move_ship(event): if event.keysym == "up": c.move(ship_id, 0, -ship_spd) c.move(ship_id2, 0, -ship_spd) elif event

How to delete the canvas from Tkinter after shown the window

社会主义新天地 提交于 2019-12-08 04:05:38
问题 I want to create a line in the Tkinter and after changing the height I need to delete the previous line and create a new line with the new height, this is a repeated process. To this, I read the tutorial of the Tkinter of python and I think the After method might be useful. So, I write my idea but it is not a good method and I cannot create it. Also, I searched about a Shown event in the Tkinter, but I did not find the Shown event in the Tkinter for the window. Here is my suggested code: from