【问题标题】:Radiobutton value is not returning in Pycharm单选按钮值未在 Pycharm 中返回
【发布时间】:2021-10-27 13:34:20
【问题描述】:

我有一个返回单选按钮值的代码,但该值没有在 pycharm 中返回。我已经尝试过 tkinter 和 pysimplegui 包。使用 IDLE 时代码返回值是否有解决此问题的方法?我的代码如下。

from tkinter import *

root=Tk()
myLabel = Label(root, text="Select type of Report(Monthly/Cummulative").pack()
r = IntVar()
print(r.get())
x = r.get()
def clicked(value):
    myLabel = Label(root, text=value)
    myLabel.pack()
    x=value
    print("x inside:", x)
    return x;  # Return tuple, we could also
    # write (str, x)

Radiobutton(root, text="Monthly Report", variable=r, value=1, command= lambda: clicked(1)).pack()
print("x outside:", x)
Radiobutton(root, text="Cummulative Report", variable=r, value=2, command= lambda: clicked(2)).pack()
myLabel = Label(root, text=r.get())
myLabel.pack()
x = clicked(x)  # Assign returned tuple
print("Value from function :",x )

root.mainloop()

【问题讨论】:

  • 如何在 pycharm 中没有返回值?
  • 您的代码在创建小部件大约一毫秒后调用r.get()clicked(x)。用户将没有机会看到这些小部件,更不用说输入它们了。

标签: python tkinter pycharm python-idle radiobuttonlist


【解决方案1】:

我使用 PyCharm 测试了您的代码。并且价值正在回归。您应该尝试重建它并对其进行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多