Python Tkinter Run Checkbuttons -
i want write python script, have checkbuttons , button running active checkbuttons. if checkbutton active , click on "run" def run_app should check checkbuttons active. if run code, terminal says, global name "is_checked" not defined.
from tkinter import * import os import sys import os.path import subprocess exe = (path of exe) call = exe class app: def __init__(self, master): self.is_checked = intvar() frame = frame(master) frame.pack() self.test = checkbutton(frame, text="verzeichnisse", ) self.test.pack(side=left) self.slogan = checkbutton(frame, text="visual studio", onvalue=1, offvalue=0, variable=self.is_checked ) self.slogan.pack(side=left) self.button = button(frame, text="run", fg="red", command=self.run_app) self.button.pack(side=left) def open_vb(self): subprocess.call(call, shell=true) def run_app(self): if self.is_checked.get(): command=self.open_vb root = tk() app = app(root) root.mainloop()
is_checked
created locally means there no is_checked
variable outside of __init__
.
if want use variable outside of created, need either make global
or bind class. since have class structure, better use latter one.
you need change is_checked
self.is_checked
everywhere make variable part of class.
Comments
Post a Comment