我想知道是否有可能在一个方法中声明一个全局变量,以便在另一个UI方法中调用和使用它。我在下面编写的代码应该获取用户选择的theresholds文件,然后在单击run按钮时将其打印出来。你知道吗
class Handler:
def on_filechooserbutton1_file_set(self, widget):
self.Thresholds = widget.get_filename()
with self.Thresholds as a:
global Thresholds
Thresholds = pd.read_table(a, sep=',')
def on_RUN_clicked(self, widget):
print Thresholds
def onDeleteWindow(self, *args):
Gtk.main_quit(*args)
builder = Gtk.Builder()
builder.add_from_file("DataAPP.glade")
builder.connect_signals(Handler())
window = builder.get_object("MainWindow")
window.show_all()
Gtk.main()
print Thresholds
thresholds变量包含一个dataframe,并且以前已经定义过,但是每当我尝试在threshold变量的方法之外调用它时,就会出现一个错误,说明:
NameError: global name 'Thresholds' is not defined
关于如何正确地做这件事有什么建议吗?你知道吗
应首先创建全局变量:
原来我打开文件的语法是错误的。要在单击按钮时和在主脚本中打印阈值文件,请使用以下代码:
相关问题 更多 >
编程相关推荐