
设计tkinter控制按钮实时生成函数图像出现问题
在代码中,模拟开关的行为时,出现了以下问题:
问题:在单击模拟开关按钮时,电压和电流从 0 时刻开始绘制,而不是从单击按钮的那一刻开始。解决方法:在 update_plot 函数中,更新 current_time_index 变量,使其与当前帧号相匹配。问题:按钮不能实现电路的断开和闭合。解决方法:在 toggle_manual_switch 函数中,更新 current_time_index 变量(在原始代码中没有更新)。在 calculate_circuit_response 函数中,调整 voltageovertime 和 currentovertime 数组的赋值逻辑,以反映开关的断开和闭合状态。
修改后的代码片段:
def toggle_manual_switch(self): # 获取当前时刻的索引 current_index = int(self.current_time_index) # FIXME: Q1.这个值没有更新过# ... 省略其他代码 ...def update_plot(self, frame): # 更新 current_time_index self.current_time_index = frame # ... 省略其他代码 ...def calculate_circuit_response(self, current_time_index): # ... 省略其他代码 ... if not self.previous_switch_state: # 开关断开 self.VoltageOverTime[current_time_index:] = 0 # FIXME: VoltageOverTime 和 CurrentOverTime 的赋值有些问题,之前是只赋值一个点? self.CurrentOverTime[current_time_index:] = 0 else: # 开关闭合 self.VoltageOverTime[current_time_index:] = V_battery * np.ones_like( self.VoltageOverTime[current_time_index:] ) self.CurrentOverTime[current_time_index:] = V_battery / R_load * np.ones_like( self.CurrentOverTime[current_time_index:] )
以上就是Tkinter实时绘图按钮控制:如何解决开关按钮无法精确控制函数图像绘制起始时间和电路状态?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1353968.html
微信扫一扫
支付宝扫一扫