tkinter-canvas

How to make a tkinter canvas rectangle with rounded corners?

╄→гoц情女王★ 提交于 2019-12-03 14:53:40
问题 I would like to create a rectangle with rounded corners. I'm using canvas from tkinter. 回答1: Offering an alternate approach to tobias's method would be to indeed do it with one polygon. This would have the advantage of being one canvas object if you are worried about optimization, or not having to worry about a tag system for referring to a single object. The code is a bit longer, but very basic, as it is just utilizing the idea that when smoothing a polygon, you can give the same coordinate

How to make a tkinter canvas rectangle with rounded corners?

…衆ロ難τιáo~ 提交于 2019-12-03 03:48:32
I would like to create a rectangle with rounded corners. I'm using canvas from tkinter. Offering an alternate approach to tobias's method would be to indeed do it with one polygon. This would have the advantage of being one canvas object if you are worried about optimization, or not having to worry about a tag system for referring to a single object. The code is a bit longer, but very basic, as it is just utilizing the idea that when smoothing a polygon, you can give the same coordinate twice to 'stop' the smooth from occuring. This is an example of what can be done: from tkinter import * root

Creating fluid movement of an oval using tkinter

旧时模样 提交于 2019-12-02 14:05:14
问题 I'm trying to create Connect-Four using tkinter. Once a disc is placed in a certain column, I want it to descend to the bottom of the column in a fluid movement. I've tried using the move command of the Canvas class but I'm unsure if I am using it incorrectly or perhaps I am better off deleting and re-drawing the oval each iteration. Currently, the disc indeed moves but not in a fluid way. It simply draws it in the new location. This is the disc moving function: counter = 0 self.__canvas

Creating fluid movement of an oval using tkinter

时光毁灭记忆、已成空白 提交于 2019-12-02 03:36:33
I'm trying to create Connect-Four using tkinter. Once a disc is placed in a certain column, I want it to descend to the bottom of the column in a fluid movement. I've tried using the move command of the Canvas class but I'm unsure if I am using it incorrectly or perhaps I am better off deleting and re-drawing the oval each iteration. Currently, the disc indeed moves but not in a fluid way. It simply draws it in the new location. This is the disc moving function: counter = 0 self.__canvas.create_oval(100,200,0,100, fill='yellow') self.__canvas.create_oval(100,300,0,200, fill='yellow') self._

Confused about Tkinter bind_class

落花浮王杯 提交于 2019-12-02 00:53:39
I define GCanvas, an extension of Canvas. My intention is to bind to GCanvas at the class level. It isn't working. I also tried to bind to tk.Canvas and it doesn't work either. Binding to root or to the GCanvas instance works fine. (Neither of this alternatives is useful to me, but I just tried them to see what happened.). Running OS X, El Capitan. import Tkinter as tk class GCanvas(tk.Canvas, object): def __init__(self, master, **kwargs): tk.Canvas.__init__(self, master, kwargs) @staticmethod def enter(e): print "enter", e.widget, e.x, e.y @staticmethod def leave(e): print "leave", e.widget

Trying to add an image that functions like a button, but this error, image “pyimage2” doesn't exist, pops up

吃可爱长大的小学妹 提交于 2019-12-01 11:22:41
I already have a set of code that is similarly formatted as the one below, and that seems to work. But somehow, the image for this one isn't popping up. And they're in the same folder as the code. Def small is the code that has the image working, and def stripes is the one that is giving me an error. from tkinter import * import tkinter as tk from tkinter import ttk def small(): s = Tk() s.title('Small Preset Shirt (Not fit to scale)') canvas = Canvas(s, width = 800, height = 100) canvas.pack() b1=ttk.Button(s,text='Click to Start', command = questions) b1.pack() photo = PhotoImage(file =

How to draw a line following your mouse coordinates with tkinter?

与世无争的帅哥 提交于 2019-12-01 10:41:10
I have tried using the following code to draw points that create a line in tkinter: import tkinter as tk from time import sleep def myfunction(event): x, y = event.x, event.y x1 = (x+1) y1 = (y+1) canvas.create_line(x, y, x1, y1) sleep(0.5) root = tk.Tk() canvas = tk.Canvas(root, width=400, height=400) canvas.pack() root.bind('d', myfunction) root.mainloop() Understandably, the program only draws a point when I press 'd'. I have tried using loops within the myfunction function like this: def myfunction(event): x, y = event.x, event.y x1 = (x+1) y1 = (y+1) for x in range(0,5): canvas.create

How to display and update a score on screen?

跟風遠走 提交于 2019-12-01 10:13:08
问题 My question is about displaying and updating text, in order to display the score on screen. I would like to create a score like the real game that would appear on the screen. But after researching Google, I have not found anyone wishing to increase a score on the screen ... Indeed, I would like the score to increase each time the bird passes between the pipes and therefore whenever the pipes have an X of 67 pixels. So does anyone know how to do this? from tkinter import * import random from

Trying to add an image that functions like a button, but this error, image “pyimage2” doesn't exist, pops up

烈酒焚心 提交于 2019-12-01 09:27:41
问题 I already have a set of code that is similarly formatted as the one below, and that seems to work. But somehow, the image for this one isn't popping up. And they're in the same folder as the code. Def small is the code that has the image working, and def stripes is the one that is giving me an error. from tkinter import * import tkinter as tk from tkinter import ttk def small(): s = Tk() s.title('Small Preset Shirt (Not fit to scale)') canvas = Canvas(s, width = 800, height = 100) canvas.pack

How to draw a line following your mouse coordinates with tkinter?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 08:23:46
问题 I have tried using the following code to draw points that create a line in tkinter: import tkinter as tk from time import sleep def myfunction(event): x, y = event.x, event.y x1 = (x+1) y1 = (y+1) canvas.create_line(x, y, x1, y1) sleep(0.5) root = tk.Tk() canvas = tk.Canvas(root, width=400, height=400) canvas.pack() root.bind('d', myfunction) root.mainloop() Understandably, the program only draws a point when I press 'd'. I have tried using loops within the myfunction function like this: def