tkinter-canvas

Method for having animated movement for canvas objects python

我的梦境 提交于 2019-11-27 08:07:14
问题 I have been trying to learn how move canvas items from google, however the method shown most places doesnt seem to work for me as intended. right now i am just trying to get a ball move from one side of the screen to the other over the period of 1 second from tkinter import * root = Tk() c = Canvas(root, width = 200, height = 100) c.pack() ball = c.create_oval(0, 25, 50, 75) for i in range(25): c.move(ball, 6, 0) root.after(40) root.mainloop() when run, this seems to move the ball before

How to bind events to Canvas items?

好久不见. 提交于 2019-11-27 04:22:01
问题 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 information about how to bind events to tags but that seems to be more indirect then what I want. I don't want to group items with tags, but rather have specific function calls when the user clicks specific items on the canvas. 回答1: To interact with

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

元气小坏坏 提交于 2019-11-27 02:31:18
问题 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, why is the top left most position in the Canvas (2,2)? It seems like it should be (0,0). My current script: from Tkinter import * master = Tk() master.configure(bg='black') master.wm_attributes("-topmost", 1) w = Canvas(master, width=150, height=40

Move a tkinter canvas with Mouse

假装没事ソ 提交于 2019-11-27 02:25:39
问题 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 the displayed area of the canvas) import Tkinter as Tk oldx = 0 oldy = 0 def oldxyset(event): global oldx, oldy oldx = event.x oldy = event.y def callback(event): # How to move the whole canvas here? print oldx - event.x, oldy - event.y root = Tk.Tk()

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

谁说我不能喝 提交于 2019-11-27 02:18:48
问题 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 parent canvas. This can easily be done if I use pack(expand = True) (which I have commented out in the code below) for the frame in the canvas but then then the scrollbar doesn't work. Here's the appropriate bit of code: self.canvas = Canvas(frame, bg

Vertical scrollbar for frame in Tkinter, Python

。_饼干妹妹 提交于 2019-11-26 22:07:50
问题 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 conclusion that a scrollbar has to be assigned to a canvas in order for it to function properly, which I have tried to include in my code but have not had much success with. The below code shows a simplified version of what I've managed to accomplish

tkinter: using scrollbars on a canvas

。_饼干妹妹 提交于 2019-11-26 20:22:17
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 fill the frame and then setting the frame size, but that presents the same problem unless I set the frame to fill the window as well, which isn't what I want. Basically, I want a fixed-size canvas with scrollbars on it. My current code looks like this (in python 3.1): from tkinter import * root=Tk() frame=Frame(root,width=300,height=300) frame.grid

tkinter: using scrollbars on a canvas

萝らか妹 提交于 2019-11-26 08:53:21
问题 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 fill the frame and then setting the frame size, but that presents the same problem unless I set the frame to fill the window as well, which isn\'t what I want. Basically, I want a fixed-size canvas with scrollbars on it. My current code looks

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

百般思念 提交于 2019-11-25 21:39:40
问题 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, this code compiles but it doesn\'t show me the image, and I don\'t know why, because it\'s the same code, in a class: import tkinter class Test: def __init__(self, master): canvas = tkinter.Canvas(master) canvas.grid(row = 0, column = 0) photo =