tkinter-canvas

python tkinter canvas when rectangle clicked

浪尽此生 提交于 2020-08-19 11:52:24
问题 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 = c.create_rectangle(75, 25, 225, 75, fill="red") playtext = c.create_text(150, 50, text="Play", font=("Papyrus", 26), fill='blue') c.pack() window.mainloop() does anyone know what I should do? 回答1: You can add tags on the items you want to bind events to. The event you want

python tkinter canvas when rectangle clicked

若如初见. 提交于 2020-08-19 11:51:29
问题 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 = c.create_rectangle(75, 25, 225, 75, fill="red") playtext = c.create_text(150, 50, text="Play", font=("Papyrus", 26), fill='blue') c.pack() window.mainloop() does anyone know what I should do? 回答1: You can add tags on the items you want to bind events to. The event you want

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

删除回忆录丶 提交于 2020-07-03 02:50:27
问题 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 everywhere, and can't seem to find a way to change the fill colour at all, and ideally I'd like to be able to do this on click. I'm actually going to be using this to change the colour of hexagons generated by a function I wrote that works fine using create

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

走远了吗. 提交于 2020-07-03 02:47:37
问题 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 everywhere, and can't seem to find a way to change the fill colour at all, and ideally I'd like to be able to do this on click. I'm actually going to be using this to change the colour of hexagons generated by a function I wrote that works fine using create

How can I save a Turtle canvas as an image (.png or .jpg) in Python 3

折月煮酒 提交于 2020-06-17 09:37:07
问题 I've been working with the turtle module and want to use it as a starting point to work on a simple image recognition program that could recognize numbers/letters. I need to be able to save the turtle as an image I could manipulate- recaling, rotating, etc. to try to regulate the images. I've been researching for hours and cannot seem to find anything that works. I have discovered how to save the Turtle output as a Tkinter canvas: import turtle t = turtle.Turtle() # Draw something canvas = t

How to put an outline on a canvas text on python — tkinter?

半城伤御伤魂 提交于 2020-05-29 11:40:42
问题 I've created a white text in the center of my canvas, but my background is very colorful and one part of it is a very light color, so some corners of my sentence doesn't appear. I can't find any options to set borders or an outline. what could I do? 回答1: Create a text item, get the bounding box of that item, use that data to create a rectangle, and raise the text above the rectangle. import Tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, background="white") canvas.pack(fill="both",

Rounded button tkinter python

拜拜、爱过 提交于 2020-05-11 05:36:05
问题 I am trying to get rounded buttons for my script using tkinter. I found the following code: from tkinter import * import tkinter as tk class CustomButton(tk.Canvas): def __init__(self, parent, width, height, color, command=None): tk.Canvas.__init__(self, parent, borderwidth=1, relief="raised", highlightthickness=0) self.command = command padding = 4 id = self.create_oval((padding,padding, width+padding, height+padding), outline=color, fill=color) (x0,y0,x1,y1) = self.bbox("all") width = (x1

tkinter.Frame.Grid sizing not displaying correctly

不羁的心 提交于 2020-04-18 06:07:02
问题 Hello I am making a table with a header for text to name the columns, cells to store data, and scrolling. The problem I'm having is that my Table is not displaying correctly. What should happen is the Headers should display above with no other space below them. (other than the small padding I added) The cells display correctly right below the headers. The scrolling works for the cells in the y direction. The scrolling also works in the x direction for both the cells and headers. The function

Python tkinter canvas flickering

丶灬走出姿态 提交于 2020-04-07 10:36:17
问题 Firstly I should state that I am aware of other posts on this site with similar names. I have been through them but they do not, so far as I can tell, address my problem. I would actually say my problem is far more simple than most of those examples. Simply put, I wanted to create a transparent rectangle that I could use to show a drag select area. When I found out that tkinter doesn't do transparency, I decided on the idea of simply drawing four lines to create the appearance of a rectangle

Python tkinter canvas flickering

浪尽此生 提交于 2020-04-07 10:32:45
问题 Firstly I should state that I am aware of other posts on this site with similar names. I have been through them but they do not, so far as I can tell, address my problem. I would actually say my problem is far more simple than most of those examples. Simply put, I wanted to create a transparent rectangle that I could use to show a drag select area. When I found out that tkinter doesn't do transparency, I decided on the idea of simply drawing four lines to create the appearance of a rectangle