わかりました、私は 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)
以下は、GUI を構築するためのコードです。
#make my root for TK
root = tk.Tk()
#make my widgets
fr = tk.Frame()
time_label = tk.Label(root, text="not started")
volt_label = tk.Label(root, text="{:0.4f} volts".format(0))
store_button = tk.Button(root, text="store Data", command=store_DAQ, state = tk.DISABLED)
start_button = tk.Button(root, text="start DAQ", command=start_DAQ)
stop_button = tk.Button(root, text="stop DAQ", command=stop_DAQ)
exit_button = tk.Button(root, text="Exit", command=exit_DAQ)