tkinter | TypeError:__init __()从1到2个位置论点,但给出了3个

发布于 2025-01-27 04:16:44 字数 410 浏览 3 评论 0原文

代码旨在将输入从TKINTER条目窗口小部件CAM1中获取,并分配给CAM1_NAME,然后将其附加到具有关联的回调功能的列表中。显然,它没有并抛出上面的错误。任何帮助将不胜感激。谢谢!


import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, cam1_name).pack()  # error happens on this line

root.mainloop()

Code is meant to take the input from the tkinter entry widget, cam1, and assign to cam1_name, to then be appended to a list with its associated callback function. Obviously, it does not and throws the error above. Any help would be appreciated. Thanks!


import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, cam1_name).pack()  # error happens on this line

root.mainloop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的呼吸 2025-02-03 04:16:44

要解决错误,您需要将文本关键字用于checkbutton的第二个参数。 checkbutton的所有选项都需要列出为key = value在父窗口参数之后。

import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, text=cam1_name).pack()

root.mainloop()

To fix the error, you need to use the text keyword for the second argument of Checkbutton. All the options for Checkbutton need to be listed as key=value after the parent window argument.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()    # my main window

def cam1_name_func():
    cam1_name.get()
    amendations["camOne"] = cam1_name

cam1_name = tk.StringVar()
cam1 = ttk.Checkbutton(root, text=cam1_name).pack()

root.mainloop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文