简体   繁体   English

在我的 python 应用程序中为 GUI 使用 Tkinter 单选按钮小部件

[英]Using the Tkinter radio-button widget for a GUI in my python application

I'm developing a python application that models forex derivatives.我正在开发一个模拟外汇衍生品的 python 应用程序。 The intent of the project is to create a GUI that can:该项目的目的是创建一个 GUI,它可以:

  • create data models创建数据模型
  • display visualizations of that data显示该数据的可视化
  • update the visuals while they're open打开时更新视觉效果
  • quit all windows with one button一键退出所有windows

This all functions as intended.这一切都按预期工作。

Currently, the GUI uses 6 Tkinter 'entry' widgets and 5 Tkinter 'button' widgets.目前,GUI 使用 6 个 Tkinter 'entry' 小部件和 5 个 Tkinter 'button' 小部件。

图形用户界面示例

'Update' buttons use (their respective) entry fields to generate 'result-sets', which are then saved to.txt files. “更新”按钮使用(它们各自的)输入字段来生成“结果集”,然后将其保存到 .txt 文件中。

'Display' buttons read data in the.txt files, and create visuals using Matplotlib's Animation function. “显示”按钮读取 .txt 文件中的数据,并使用 Matplotlib 的 Animation function 创建视觉效果。

What I want to do: replace the 'size' entry field with: radio-button / checkbox / slider Tkinter widgets.我想要做的:将“大小”输入字段替换为:单选按钮/复选框/slider Tkinter 小部件。

For example: Consider a user who wants to model the purchase of 10 forex contracts.例如:考虑一个用户想要 model 购买 10 份外汇合约。 Instead of typing 10 into the 'size' field (and clicking update), they mark the 10 radio-button and click 'update'.他们没有在“大小”字段中输入 10(并单击更新),而是标记 10 单选按钮并单击“更新”。

What I've attempted and failed to do: I've read a number of Tkinter radio-button / checkbox widget tutorials which have been a waste of time.我尝试过但没有做的事情:我已经阅读了许多 Tkinter 单选按钮/复选框小部件教程,这些教程浪费了时间。 Honestly, I'm struggling to conceptualize how I can add this functionality.老实说,我正在努力构思如何添加此功能。

If applicable, the GUI is formatted by a class.如果适用,GUI 由 class 格式化。

The best approach imo would be a slider. imo 最好的方法是 slider。

slider = tk.Scale(master, from_=0, to=10, orient=HORIZONTAL)

and then later make a function to get that chosen value from slider like:然后再制作一个 function 以从 slider 中获取所选值,例如:

size = slider.get()

Have a good day.祝你有美好的一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM