我想创建一个由列表框所选项目的更改或单选按钮所选项目的更改触发的事件。是否可以?我使用这段代码:
def getScript(event):
state = rb.get()
listScript = []
processor = ()
processor = lb1.get(lb1.curselection())
if processor :
if (state == 1):
print processor
if (state == 2):
pass
if (state == 3):
pass
frame2 = Frame(top)
frame2.pack(fill = X)
rb = IntVar()
R1 = Radiobutton(frame2, text = "Parallel Test",
variable = rb, value = 1, command = getScript)
R2 = Radiobutton(frame2, text = "Non Parallel Test",
variable = rb, value = 2, command = getScript)
R3 = Radiobutton(frame2, text …Run Code Online (Sandbox Code Playgroud) 我想要一个类变量,以便可以在所有实例中访问该值,但我还想在类中的方法中访问该变量.那可能吗?我试过这个,但它根本不起作用.
class myClass:
myvariable = 1
def add():
myvariable+= 1
def print1():
print myvariable
Run Code Online (Sandbox Code Playgroud)
我想制作两个实例,一个只做add方法,另一个只做print1方法
我正在尝试更改跨类的全局变量。这是我的代码:
文件main.py
import class2
class first:
def changeA(self):
global a
print a
a += 2
print a
test0 = first()
test1 = class2.second()
test2 = first()
test3 = class2.second()
test0.changeA()
test1.changeA()
test2.changeA()
test3.changeA()
Run Code Online (Sandbox Code Playgroud)
文件class2.py
a = 1
class second:
def changeA(self):
global a
print a
a += 1
print a
Run Code Online (Sandbox Code Playgroud)
但它返回一个错误:全局名称'a'未定义。有没有适当的方法来访问和更改python中跨文件的全局变量?提前致谢