如何将 stringVar() 从 tk 转换为 pyqt [英] How to convert stringVar() from tk to pyqt

查看:39
本文介绍了如何将 stringVar() 从 tk 转换为 pyqt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此功能作为代码的一部分,我正在尝试从 tk 迁移到 pyqt,但我在 pyqt 方面没有太多经验.我正在尝试生成 Tkinter 字符串变量列表来存储条目.

I have this function as part of my code and I am trying to move from tk to pyqt, but I do not have much experience in pyqt. I am trying to generate a list of Tkinter string variables to store the entries.

def generate_stringvars(self):
    temp_entriesx = []
    count = 0
    while count < 21:
        e = tk.StringVar()
        e.set("")
        temp_entriesx.append(e)
        count += 1
    return temp_entriesx

如何更改 tk.StringVar() 以使其在 pyqt 中工作?

How do I change tk.StringVar() to make it work in pyqt?

谢谢

推荐答案

pyQt 和 Qt 之间存在一些差异.一个重要的区别是没有明确需要 QString(见此处).pyQt 与 Python 内置字符串类型完全兼容.您的代码将如下所示.

There are a few differences between pyQt and Qt. One important difference is that there is no explicit need for QString (see here). pyQt is fully compatible with Python built-in string type. Your code will look something like this.

def generate_stringvars(self):
    temp_entriesx = []
    count = 0
    while count < 21:
        temp_entriesx.append("")
        count += 1
    return temp_entriesx

这篇关于如何将 stringVar() 从 tk 转换为 pyqt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆