Posts

Showing posts with the label tkinter

How to get the clicks coordinates python 3

How to get the clicks coordinates python 3 I am making a cross-zero game on python 3.5.4 with tkinter. I have made this at the moment: from sys import * from tkinter import * screen = Tk() c = Canvas(width=600, height=600) c.pack() Line1 = c.create_line(200, 0, 200, 600) Line2 = c.create_line(400, 0, 400, 600) Line3 = c.create_line(0, 200, 600, 200) Line4 = c.create_line(0, 400, 600, 400) Then, I want to make to make the main loop. And I think that it'll be better if I make it with using clicks' coordinates. But how can I get them? Or maybe I should make the game with using buttons? 1 Answer 1 Here is one way to access the canvas coordinates of a mouse click: import tkinter as tk def click(event): print(event.x, event.y) if __name__ == '__main__': screen = tk.Tk() canvas = tk.Canvas(width=600, height=600) canvas.pack() canvas.bind('<Button-1>', click...

How to stop the mainWindow while opened a new Window and get my Value

How to stop the mainWindow while opened a new Window and get my Value My problem is that i have an Main-Class with an button-click function, where if i click the button, the EntryBox will be opened and in the button-click function i want to create the folder too, but i dont know how to "stop" the mainWindow while the EntryBox-Window is open to get the value(Folder name). @BryanOakley Minimal, Complete, and Verifiable example: That's my msBox.py import tkinter as tk FolderName = "" class EntryBox: def __init__(self, Text): self.root = tk.Tk() self.textBox = tk.Entry(self.root) self.EBOKAY = tk.Button(self.root, text="Okay") self.EBOKAY.bind("<Button-1>", self.EBOKAY_click) self.EBLabel = tk.Label(self.root, text=Text) self.EBLabel.pack() self.textBox.pack() self.EBOKAY.pack() self.root.mainloop() def EBOKAY_click(self, event): global FolderName FolderName = self.textBox.get() self.root.dest...

Install tkinter in python3.6 on Ubuntu

Install tkinter in python3.6 on Ubuntu +--------+-----------------------------------+ | OS | Ubuntu 12.04 | +--------+-----------------------------------+ | Python | 2.7, 3.2 and source installed 3.6 | +--------+-----------------------------------+ Since there are 2 versions of Python 3, anything installed from the repository doesn't work for Python 3.6. The latest version of Python in the repositories is 3.2, so I need source installs or through pip3.6. After starting python3.6 I tried to import tkinter , which gave the following error. Even though help('modules') returned a list of modules which included tkinter. python3.6 import tkinter help('modules') import tkinter ModuleNotFoundError: No module named '_tkinter' I tried doing the same in python3.2 and there were no errors . tkinter._tkinter gave the location of tkinter library for python3.2 python3.2 tkinter._tkinter I cd'd into the python3.6 directory which has all ...

Python: How to change data type and override a variable from imported module

Python: How to change data type and override a variable from imported module I have two python programs in same folder named main.py and tk_version.py I am importing main.py in tk_version.py I have a variable in main.py which has default value lets say 'xyz' Now in tk_version.py I am taking the value for the variable from user using Tkinter GUI. So what I want is when main.py is executed the constant value must be taken and when tk_version.py is executed the value given by user override the default value. Example: main.py var="default" def show(): print(var) if __name__ == '__main__': show() tk_version.py from tkinter import * import main Main = Tk() var= StringVar() def e1chk(): global var var = e1.get() main.show() return e1=Entry(Main,textvariable=var,width=50) e1.grid(row=0,column=5,sticky=NSEW) b1=Button(Main,text="Save",command=e1chk) b1.grid(row=0,column=8,sticky=NSEW) Main.mainloop() OUTPUT for main.py >>> ==...

Python Tkinter Error, “Too Early to Create Image”

Python Tkinter Error, “Too Early to Create Image” So I have an assignment that I have to use Tkinter to create a board game. This is just one part of the program where I want to bring in the image of the board. But I keep on getting the error, "Too early to create image" and I'm not sure what I'm doing wrong. Here's my code so far: from Tkinter import * from pprint import pprint # Which variable is currently updating from variableColors import Variables VariableIndex = 0 VariableText = Variables[VariableIndex] Ids = None # Current canvas ids of the text and 4 player tokens: # Will be None if not committed VariableCoords = { } # Where store variable and coordinates im = PhotoImage(file="C:UsersKikiDesktopAssignment\") photo = can.create_image(0,0,anchor=NW, image=im) can.pack() root.mainloop() Any help would be appreciated. Thanks :) 1 Answer ...