create the variables
region = {'top': tk.IntVar(), 'left': tk.IntVar(), 'right': tk.IntVar(), 'bottom': tk.IntVar()}
create the entrys and connect to the variabless
tk.Entry(master, textvariable=region['top']).place(x=60, y=100)
tk.Entry(master, textvariable=region['left']).place(x=60, y=120)
tk.Entry(master, textvariable=region['right']).place(x=60, y=140)
tk.Entry(master, textvariable=region['bottom']).place(x=60, y=160)
I use the variables on some functions
def get_region():
np.array(ImageGrab.grab(bbox=(region['top'].get(), region['left'].get(), region['right'].get(), region['bottom'].get())))
And use the variables to save and open profiles on the app
def open_file(self):
with open('{}'.format(filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("json files", "*.json"),
("all files", "*.*")))), 'r') as config:
data = json.load(config)
region['top'].set(data['region']['top'])
region['left'].set(data['region']['left'])
region['right'].set(data['region']['right'])
region['bottom'].set(data['region']['bottom'])
def save_as(self):
json.decoder = {
'region': {
'top': region['top'].get(),
'left': region['left'].get(),
'right': region['right'].get(),
'bottom': region['bottom'].get(),
},
}
with open('{}'.format(filedialog.asksaveasfilename(initialdir="/", title="Save file",
filetypes=(("json files", "*.json"),
("all files", "*.*")))), 'w',
encoding='utf-8') as config:
json.dump(json.decoder, config, ensure_ascii=False, indent=2)
config.close()
What I use in PyQt5 instead of the IntVar() to structure like this?