好吧,我是C,VisualBasic和Fortran程序员(是的,我们仍然存在).我错过了Python 3.2的范例.在下面的代码中,为什么我的函数start_DAQ看不到我的所有全局变量?该功能似乎让自己的局部变量do_DAQ,data_index和start_time,但不会store_button.我已经阅读了几个类似问题的回复,仍然没有得到它.我想我可以使用全局声明,但被告知这是不好的做法.
#-----------------------------------------------------------------------
# define my globals
#-----------------------------------------------------------------------
#make an instance of my DAQ object and global start_time
myDaq = DAQ_object.DAQInput(1000,b"Dev2/ai0")
start_time = time.time()
#build data stuctures and initialize flags
time_data = numpy.zeros((10000,),dtype=numpy.float64)
volt_data = numpy.zeros((10000,),dtype=numpy.float64)
data_queue = queue.Queue()
data_index = 0
do_DAQ = False
#-----------------------------------------------------------------------
# define the functions associated with the buttons
#-----------------------------------------------------------------------
def start_DAQ():
do_DAQ = True
data_index=0
start_time = time.time()
store_button.config(state = tk.DISABLED)
Run Code Online (Sandbox Code Playgroud)
下面是一些用于构建GUI的代码
#make my …Run Code Online (Sandbox Code Playgroud)