0
I have two Tkinter Windows, and I want to pass the dice from one window to the other window.
Code from the first Window:
from tkinter import *
from get_pos_mouse import Get_Mouse_Pos
class Application():
def __init__(self, master=None):
self.master = master
self.bt = Button(self.master, text='+')
self.bt.bind("<ButtonRelease-1>", self.new_window)
self.bt.pack()
self.lb = Label(self.master, text='Pos Here:')
self.lb.pack()
def new_window(self, event=None):
self.new_window = Toplevel(self.master)
self.app = Get_Mouse_Pos(self.new_window)
def change_lb(self, pos):
self.lb.config(text=pos)
if __name__ == "__main__":
root = Tk()
app = Application(root)
root.mainloop()
Code of the second Window:
import pyautogui
from tkinter import *
class Get_Mouse_Pos():
def __init__(self, master):
self.master = master
self.master.overrideredirect(1)
self.master.wm_attributes('-transparentcolor', 'yellow')
self.master.attributes("-topmost", True)
self.master.bind("<Escape>", self.safe_quit)
self.screenWidth, self.screenHeight = pyautogui.size()
self.canvas_total = Canvas(
self.master, width=self.screenWidth, height=self.screenHeight, bg='yellow')
self.canvas_total.bind("<Button-1>", self.get_pos_mouse)
self.canvas_total.pack()
self.draw_lines()
def draw_lines(self):
x, y = pyautogui.position()
self.canvas_total.delete("all")
self.canvas_total.create_line(
0, y, self.screenWidth, y, fill="red", width=2)
self.canvas_total.create_line(
x, 0, x, self.screenHeight, fill="red", width=2)
self.master.after(20, self.draw_lines)
def get_pos_mouse(self, event=None):
pos = (event.x, event.y)
self.safe_quit()
def safe_quit(self, event=None):
self.master.destroy()
The goal was that when the "get_pos_mouse()" function of the second window was called the "change_lb()" function of the first window was also called.