I am new to the world of programming. You can help me understand how I can use an instance variable globally. In this case I would like to use the variables self.x and self.y outside the class. Thanks !!!
import tkinter as tk
import win32gui
from PIL import ImageGrab
class TestApp:
def __init__(self, master):
frame = tk.Frame(master)
frame.pack()
self.master = master
b1 = tk.Button(text='ok', command=self.pressed)
b1.pack()
def pressed(self):
self.x = ventana.winfo_x()+7
self.y = ventana.winfo_y()+30
print('tkinter location: ({},{})'.format(self.x, self.y))
ventana = tk.Tk()
ventana.title("Palynology")
ventana.geometry('300x300')
ventana.configure(background='blue')
ventana.attributes('-alpha', 0.5)
app = TestApp(ventana)
ventana.mainloop()
#img = ImageGrab.grab(bbox=(x,y,x+300,y+300)) #x1, y1, x2, y2
#img.show()