tkinter-canvas

Tkinter: How to make a rounded corner text widget?

女生的网名这么多〃 提交于 2019-12-18 18:11:50
问题 Question How to create a rounded corner text widget? I think I have an idea of creating a rounded canvas and fill the entire canvas with the text box with no border. Problem The code to create a rounded border canvas is not working when I try to extend the height and width of the canvas. The line breaks and becomes discontinuous. The code to create rounded corner canvas is taken from How to make a tkinter canvas rectangle with rounded corners? My code with custom width and height def rounded

Tkinter | Custom widget: Infinite (horizontal) scrolling calendar

怎甘沉沦 提交于 2019-12-18 09:49:45
问题 CONTEXT I am trying to create a custom calendar (Tkinter widget) that has these following attributes/features: Each column represents 1 day Each row will represent a person It has infinite horizontal scrolling -> so it can go infinitely to the past and present the cells (boxes) in the calendar are going to be interactive in a way that if I hold down Left-Mouse-Button , I can select specific cells for further operation/function It would look something like this: (Note to the image: the RED

Sort Algorithm Visualization: How to pull values to animate the canvas, from inside a tight loop

*爱你&永不变心* 提交于 2019-12-18 09:15:12
问题 I am working on a visualization of different sorting algorithms using the height of different bars with tkinter. I have been able to shuffle the bars and also sort them after some help. The problem I am having now is slowing the sorting of the bars down so it can be seen how each algorithm works. Here is what I have so far: import tkinter as tk import random def swap_two_pos(pos_0, pos_1): Bar1x1, _, Bar1x2, _ = canvas.coords(pos_0) Bar2x1, _, Bar2x2, _ = canvas.coords(pos_1) canvas.move(pos

How to bind a click event to a Canvas in Tkinter? [closed]

六眼飞鱼酱① 提交于 2019-12-17 19:35:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I was just wondering if there was any possible way to bind a click event to a canvas in 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, yet I have not found a way to bind a click event on a canvas. 回答1:

Tkinter canvas zoom + move/pan

若如初见. 提交于 2019-12-17 09:40:20
问题 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 work for bitmap images on the canvas Fortunately, this method allows zooming of images (by manually redrawing the zoomed portion of the image). But: As we are redrawing a particular portion of the canvas, move/pan feature won't work anymore... We

How do I have an object rebound off the canvas border?

早过忘川 提交于 2019-12-13 23:33:44
问题 I am using the canvas widget from tkinter to create an ellipse and have it move around in the canvas. However when the ellipse comes in contact with the border it gets stuck to wall instead of bouncing off. I'm struggling with debugging the code, thanks in advance! from tkinter import * from time import * import numpy as np root = Tk() root.wm_title("Bouncing Ball") canvas = Canvas(root, width=400, height=400, bg="black") canvas.grid() size=10 x = 50 y = 50 myBall = canvas.create_oval(x-size,

“Stop” Button in Tkinter

孤人 提交于 2019-12-13 22:55:54
问题 I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far: import turtle import tkinter as tk def start(): t.forward(100) t.right(90) t.forward(100) t.left(90) t.forward(100) t.right(90) t.forward(100) t.right(90) t.forward(100) def stop(): t.stop def clear(): canvas.delete("all") root = tk.Tk() canvas = tk.Canvas(width = 500, height = 500) canvas.pack()

Graded combobox Menu Python Tkinter

谁说我不能喝 提交于 2019-12-13 07:28:12
问题 How to make a graded combobox in python Tkinter? Like if we choose a value from first combobox menu, then the next combobox menu will show only values that inside the first selected combobox value category. This is my code: BU = StringVar() BU.set("") def BU(BU_choices): s = BU.get() BU_choices = ["DUM", "IND", "KAM", "RAP"] BU_drop = OptionMenu(Canv, status, *BU_choices, command=BU) BU_drop.config(bg="white", fg="dark blue", width=3, relief=GROOVE) BU_drop.place(x=130, y=110) sector =

I am attempting to code a card game in Python and want to place an image, but the image wont appear on the canvas in Tkinter

↘锁芯ラ 提交于 2019-12-13 06:51:27
问题 from Tkinter import * frame = Tk() frame.geometry("1200x900") w = Canvas(frame,width=250,height=450) w.place(x=30,y=300) img=PhotoImage(file="card2.ppm") w.create_image(100,100,anchor=NW,image=img) frame.mainloop() 回答1: The PhotoImage class can read GIF and PGM/PPM images from files: photo = PhotoImage(file="image.gif") photo = PhotoImage(file="lenna.pgm") The PhotoImage can also read base64-encoded GIF files from strings. You can use this to embed images in Python source code (use functions

Canvas bbox method returns None although widgets exist inside

柔情痞子 提交于 2019-12-13 03:49:05
问题 In tkinter, I'm trying to make a scrollable canvas that contains widgets so my fixed-size window can scroll to use all the widgets. However, when attempting to set the scrollbar size by getting the bounding box size from the Canvas, None is returned. My widgets are being added to the canvas by assigning their parent as the canvas and calling grid() on each. I try to get the bounding box size after creating and laying out the widgets. # Create vertical scrollbar self.scrollbar = Scrollbar(self