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
12
votes
1 answer

How to insert an image in a canvas item?

I am working on a game project for school, which look like this : In-game aspect I have created these colored polygons like this : ship = can.create_polygon(410,650,450,600,490,650 , fill= 'red' , outline='black') ennemies =…
Milky_Way
  • 149
  • 1
  • 2
  • 7
12
votes
2 answers

Tkinter: how to colorize the outline of a canvas rectangle?

I draw a rectangle on a Canvas: canvas = Canvas(parent, cursor="cross") rect = canvas.create_rectangle(20,20, 1, 1, fill="") I only want to draw the border, leaving the interior transparent (that is why I set fill="" as mentioned here). My…
user4772964
12
votes
2 answers

Tkinter Canvas move item to top level

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…
Peter Kramer
  • 192
  • 1
  • 1
  • 10
11
votes
1 answer

python tkinter canvas when rectangle clicked

I've been trying to make a function run when I click a rectangle on a tk canvas. Here is the code: from tkinter import * window = Tk() c = Canvas(window, width=300, height=300) def clear(): canvas.delete(ALL) playbutton =…
Random Person
  • 399
  • 1
  • 3
  • 9
11
votes
2 answers

How do I find out the size of a Canvas text object in tkinter?

I want to create some text in a canvas: myText = self.canvas.create_text(5, 5, anchor=NW, text="TEST") Now how do I find the width and height of myText?
Matt Gregory
  • 8,074
  • 8
  • 33
  • 40
10
votes
2 answers

How to make a Button using the tkinter Canvas widget?

I want to obtain a button out of a Canvas. I've tried to pack the canvas in the button widget, but that didn't work. Googling a bit, I've found (here: How do you create a Button on a tkinter Canvas?) that the Canvas method create_window might help.…
Zagorax
  • 11,440
  • 8
  • 44
  • 56
9
votes
1 answer

Vertical and Horizontal Scrollbars on Tkinter Widget

I am trying to output the contents of a database to a Tkinter widget. The database has enough rows and columns to where I need to have both horizontal and vertical scrollbars enabled, but I am having a hard time getting horizontal and vertical…
lajulajay
  • 355
  • 3
  • 4
  • 18
9
votes
1 answer

Change the width of a rectangle in tkinter's canvas widget

I've tried several ways to change the width of the blue rectangle in this example code. Nothing seems to work. In the code, "a" represents a float variable between 1.00, and 0.00. That value is used to calculate "b," which is the desired width of…
Chris F
  • 101
  • 1
  • 1
  • 6
9
votes
2 answers

tkinter winfo_screenwidth() when used with dual monitors

With tkinter canvas, to calculate the size of the graphics I display, I normally use the function winfo_screenwidth(), and size my objects accordingly. But when used on a system with two monitors, winfo_screenwidth() returns the combined width of…
Karpov
  • 403
  • 1
  • 6
  • 11
9
votes
1 answer

Move a tkinter canvas with Mouse

I would like to move a whole tkinter Canvas with Mouse Click (hold) + Motion of the mouse. I tried with canvas.move but it doesn't work unfortunately. How can I scroll in the whole canvas ? (not move each element of the canvas, but rather scroll…
Basj
  • 41,386
  • 99
  • 383
  • 673
9
votes
4 answers

How to open PIL Image in Tkinter on Canvas

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 =…
user164814
  • 135
  • 2
  • 2
  • 5
9
votes
1 answer

Tkinter Canvas create_window()

I'm trying to use Tkinter Canvas (self._canvas) to create window using create_window function. The window field for that function is a Tkinter Frame (self._tableFrame). Can someone please help me out on how to make self._tableFrame to expand to size…
markfw
  • 683
  • 2
  • 9
  • 22
8
votes
1 answer

How to convert Tkinter canvas coordinate to window?

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, which is done like this: x = canvas.canvasx(event.x)
Marcos Saito
  • 530
  • 2
  • 10
  • 17
8
votes
2 answers

tkinter Canvas window size

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…
Alberto Vassena
  • 825
  • 1
  • 10
  • 13
8
votes
2 answers

Vertical scrollbar for frame in Tkinter, Python

My aim is to have a scrollbar that stays at the right-side of a full-screen window, allowing the user to scroll up and down through various different widgets (such as labels & buttons). From other answers I've seen on this site, I've come to the…
Luke25361
  • 155
  • 2
  • 3
  • 9