Questions tagged [tkinter-canvas]

The Canvas widget provides structured graphics facilities for Tkinter. This is a highly versatile widget which can be used to draw graphs and plots, create graphics editors, and implement various kinds of custom widgets.

The Canvas widget provides structured graphics facilities for Tkinter. This is a highly versatile widget which can be used to draw graphs and plots, create graphics editors, and implement various kinds of custom widgets.

The canvas is a general purpose widget, which is typically used to display and edit graphs and other drawings.

Another common use for this widget is to implement various kinds of custom widgets. For example, you can use a canvas as a completion bar, by drawing and updating a rectangle on the canvas.

The Canvas is the only scrollable widget in Tkinter. This is useful for more complicated GUIs where there may not be enough space for all the widgets.

Source

1963 questions
86
votes
5 answers

Why does Tkinter image not show up if created in a function?

This code works: import tkinter root = tkinter.Tk() canvas = tkinter.Canvas(root) canvas.grid(row = 0, column = 0) photo = tkinter.PhotoImage(file = './test.gif') canvas.create_image(0, 0, image=photo) root.mainloop() It shows me the image. Now,…
thomas.winckell
  • 1,217
  • 1
  • 10
  • 16
58
votes
3 answers

How to clear Tkinter Canvas?

When I draw a shape using: canvas.create_rectangle(10, 10, 50, 50, color="green") Does Tkinter keep track of the fact that it was created? In a simple game I'm making, my code has one Frame create a bunch of rectangles, and then draw a big black…
Taylor Hill
  • 1,053
  • 1
  • 14
  • 24
51
votes
3 answers

How do I remove the light grey border around my Canvas widget?

I've been messing with the Tkinter Canvas widget in order to see if I could make some aesthetically pleasing widgets, and I have a few questions. First, why is there a light grey border around my Canvas widget, and how do I get rid of it? Secondly,…
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
39
votes
11 answers

How to draw polygons with Python?

I have input values of x, y coordinates in the following format: [[1,1], [2,1], [2,2], [1,2], [0.5,1.5]] I want to draw polygons, but I don't know how to draw them! Thanks
W.Fan
  • 407
  • 1
  • 4
  • 3
34
votes
4 answers

Tkinter canvas zoom + move/pan

Tkinter's canvas widget has built-in features to: move/pan the canvas (for example with Click + Drag) with canvas.scan_mark and canvas.scan_dragto, see this question zoom the vector elements on the canvas with canvas.scale, but sadly, this doesn't…
Basj
  • 41,386
  • 99
  • 383
  • 673
34
votes
1 answer

How to bind events to Canvas items?

If I'm using a canvas to display data and I want the user to be able to click on various items on the canvas in order to get more information or interact with it in some way, what's the best way of going about this? Searching online I can find…
Ian
  • 363
  • 1
  • 4
  • 6
33
votes
2 answers

tkinter: using scrollbars on a canvas

I'm trying to make a canvas scrollable. However, once I try to set up scrollbars to work with the canvas, tkinter seems to completely ignore the dimensions I initially set for my canvas. I've tried packing them all in a frame, setting the canvas to…
28
votes
3 answers

Tkinter: How to get frame in canvas window to expand to the size of the canvas?

So I've been using the canvas widget in tkinter to create a frame full of labels which has a scrollbar. All is working good except that the frame only expands to the size of the labels placed in it - I want the frame to expand to the size of the…
Jay Jen
  • 705
  • 1
  • 7
  • 11
23
votes
1 answer

How to bind a click event to a Canvas in Tkinter?

I was just wondering if there was any possible way to bind a click event to a canvas using Tkinter. I would like to be able to click anywhere on a canvas and have an object move to it. I am able to make the motion, but I have not found a way to…
lukejano
  • 301
  • 1
  • 4
  • 12
19
votes
7 answers

How to make a rounded button tkinter?

I am trying to get rounded buttons for my script using tkinter. I found the following code in an answer to How to make a Button using the tkinter Canvas widget?: from tkinter import * import tkinter as tk class CustomButton(tk.Canvas): def…
Martinn Roelofse
  • 423
  • 2
  • 4
  • 13
19
votes
1 answer

Python Tkinter Embed Matplotlib in GUI

I'm trying to embed a plot in my Tkinter GUI coded in Python. I believe the code below succeeds in simply putting a graph into a canvas, but I don't have any control of the canvas location within the GUI grid. I want to be able to have a subsection…
thenickname
  • 6,684
  • 14
  • 41
  • 42
17
votes
1 answer

How to update the contents of a FigureCanvasTkAgg

I'm plotting some data in a Tkinter FigureCanvasTkagg using matplotlib. I need to clear the figure where I plot data and draw new data when a button is pressed. Here is the plotting part of the code (there's an App class defined before): …
Copo
  • 181
  • 1
  • 2
  • 6
15
votes
3 answers

How to make a tkinter canvas rectangle with rounded corners?

I would like to create a rectangle with rounded corners. I'm using canvas from tkinter.
Cthulhu
  • 699
  • 1
  • 10
  • 21
15
votes
1 answer

Can you change the attributes of a Canvas object after creation?

I'm trying to simulate an American traffic light, with 3 circles on a rectangle, all drawn on a set Canvas. The simulation is supposed to mirror "animation" by changing which light is displayed every 2 seconds in the following order: green > yellow…
Brad Rice
  • 1,334
  • 2
  • 17
  • 36
13
votes
1 answer

Changing the colour on click of a tkinter rectangle on click in python

So I have this code which draws a simple rectangle: from tkinter import * root = Tk() canvas = Canvas(root, width = 500, height = 500) canvas.pack() canvas.create_rectangle(100, 100, 400, 400, fill='black') mainloop() Now I've been looking…
SyShiv
  • 131
  • 1
  • 1
  • 3
1
2 3
99 100