【发布时间】:2020-11-06 10:21:00
【问题描述】:
大家好!
我创建了一个 tkinter 界面,其中 3 个按钮在 cliqued 后启动 3 个不同的功能。每个函数都从不同位置(COM 端口和 Selenium/webdriver)重新获取数据。
通过这个不同的函数,我想更新我打算稍后打印的变量,但是当我尝试在每个函数的末尾使用“return”时,这不起作用。
因此,我认为我的结构是错误的,但我不明白如何,请您帮忙理解这里的问题吗?
import tkinter as tk
stack_lenght = 0
frequency_P = 0
frequency_S1 = 0
frequency_S2 = 0
stack_power = 0
amplitude1 = 0
amplitude2 = 0
amplitude3 = 0
amplitude4 = 0
def Get_lenght():
#my code
return stack_lenght = lenght_measure
def Get_frequencies():
#my code
return frequency_P = Frequency_measured
def Get_amplitudes():
#my code
....
# My Tkinter interface bellow
谢谢!
【问题讨论】:
-
您可能想使用
global,因为在函数内部所做的更改是在本地范围内,不会在函数外部生效。
标签: python function variables tkinter