tkinter-canvas

Remove automatic gap between gridded python Tkinter widgets

柔情痞子 提交于 2020-01-11 12:50:06
问题 I'm using python2 on Windows. When I run the followig code, I get a gap between the two canvas (see picture below), although there is no padding specified when I grid them. Is there any possibility to remove this? import Tkinter as tk import ttk class App(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.c1 = tk.Canvas(master=self, background='white', borderwidth=0, relief=tk.FLAT) self.c2 = tk.Canvas(master=self, background='white', borderwidth=0, relief

Tkinter moving balls program creating 4 balls instead of 2

强颜欢笑 提交于 2020-01-07 04:22:22
问题 I have created a program that made a ball move around a canvas and bounce of the edge of the canvas. This worked very well so I tried to add another ball but instead of creating 2 balls it created 4, 2 of the balls move and the other two stay still. This is the code: #imports from tkinter import * import random from random import randint #Creating random x and y for the balls to move along x = random.randint(1,10) y = random.randint(1,10) print(x, " Ball 1y") print(y, " Ball 1x") x0 = random

Python Tkinter canvas rectangle with an image

时光毁灭记忆、已成空白 提交于 2020-01-07 02:57:09
问题 Hello I would like to know how can I fill a canvas.rectangle with an image but not a colour. This is my codes : def P1(): def square(): x1,y1,x2,y2=0,675,75,750 for i in range(0,10): for f in range(0,10): can1.create_rectangle(x1,y1,x2,y2,fill="blue") x1=x1+75 x2=x2+75 list.append((x1,x2,y1,y2)) x1,x2=0,75 y1=y1-75 y2=y2-75 can1.create_rectangle(x1,y1,x2,y2,fill="blue") list.append((x1,x2,y1,y2)) Thanks. 回答1: You can't replace the fill with something like fillImage because it doe not exists.

Deleting contents of a Tkinter canvas text item

南笙酒味 提交于 2020-01-06 05:05:27
问题 As shown below, Function 1 calls another function (draw_text) so that I can display my output / result to a label within the canvas out my GUI. This all work great (thanks to Stack Overflow!!) # Function 1 def Relay_1(): arduinoData.write(b'1') draw_text(self,'This is a Test') # Function 2 def Relay_(): arduinoData.write(b'1') draw_text(self,'This is another test number 2') #Function 3 def draw_text(self, text): self.canvas.create_text(340,330,anchor = 'center',text = text, font = ('Arial',

Increase tkSimpleDialog window size

那年仲夏 提交于 2020-01-04 05:33:32
问题 How do i increase or define window size of tkSimpleDialog box ? import Tkinter, tkSimpleDialog root = Tkinter.Tk() root.withdraw() test = tkSimpleDialog.askstring("testing", "Enter your search string text") print test 回答1: Starting from: http://effbot.org/tkinterbook/tkinter-dialog-windows.htm I did the following: import Tkinter as tk, tkSimpleDialog class MyDialog(tkSimpleDialog.Dialog): def body(self, master): self.geometry("800x600") tk.Label(master, text="Enter your search string text:")

Use matplotlib pick event to trigger when center of pcolormesh squares are clicked?

你说的曾经没有我的故事 提交于 2020-01-03 04:32:11
问题 I am working on a broader project, but am running into an issue using matplotlibs picker=True and pick_event with a pcolormesh. It works, but is not intuitive as the pick event is only triggered when i click along the edges of the heatmap 'boxes', and it returns the surrounding indices (so if you click a corner 4 indices are returned by the intersection of the 4 boxes at that point). For example, in the following picture when I click near the yellow circle my picker returns indices [5 8] (5

Confused about Tkinter bind_class

半世苍凉 提交于 2019-12-31 03:03:06
问题 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)

How to clear Tkinter Canvas?

浪尽此生 提交于 2019-12-29 03:32:11
问题 When I draw a shape using: canvas.create_rectangle(10, 10, 50, 50, color="green") Does Tkinter keep track of the fact that it was created? In a simple game I'm making, my code has one Frame create a bunch of rectangles, and then draw a big black rectangle to clear the screen, and then draw another set of updated rectangles, and so on. Am I creating thousands of rectangle objects in memory? I know you can assign the code above to a variable, but if I don't do that and just draw directly to the

Saving a large turtle graphics image from the entire canvas, not just the window

泄露秘密 提交于 2019-12-25 01:22:20
问题 After looking for answers all around, I find lots of help and guidance on how to save a file either using turtle screen or tkinter canvas mixed with the turtle module. I'm drawing a large image and the windows size is fine and scrollable, letting me see the entire image. But when I try to save the image to postscript, I only get the window view, not the entire canvas. Cannot find out how to proceed, any tips? There might be an answer in How can I convert canvas content to an image? but I

insert text on image, python

有些话、适合烂在心里 提交于 2019-12-24 08:51:28
问题 My project is about loading an image and when I click on a button, a text area appears in the image, and I can write a text on it and later on save the text written on the image and the image. To do so I used tkinter but I set my image as background and I added a text box( text widget ) and enter a text, but obviously I can't save that image( the one set as background) and the text written on it. I tried using PIL but i didn't find what I was looking for. This is my code using tkinter : from