【问题标题】:Unknown option yscrollcommand未知选项 yscrollcommand
【发布时间】:2021-01-17 03:39:30
【问题描述】:

我正在使用 TKinter 模块创建计费软件。我面临一个未知选项的问题。我正在向 Frame2 添加一个滚动条,因为我想添加多个项目,所以会发生这样的错误。如果有人可以帮助我...??

    from tkinter import*
    from tkinter import messagebox,ttk
    import math,random,os
    class Bill:
        def __init__(self,root):
            self.root = root
            self.root.geometry("1350x700+0+0")
            self.root.title("Billing Software") 
            bg_color = "#074463"
            title = Label(self.root,text="BILLINGSOFTWARE",bd=12,relief=GROOVE,
            bg=bg_color,fg="white",font=("times new roman",30,"bold"))
            title.grid(ipadx=463)
            F2= Frame(self.root,relief=GROOVE,bd=10,bg=bg_color)
            F2.place(x=5,y=180,width=864,height=380)
            scroll_y = Scrollbar(F2,orient=VERTICAL)
            self.fr = Frame(F2,yscrollcommand=scroll_y.set) 
            scroll_y.grid(row=5,column=0,padx=10,pady=50)          
            scroll_y.config(command=self.fr.yview)
            self.fr.grid(row=1,column=2,padx=10,pady=10)                
    
          
            it1_lbl=Label(F2,text="item1",font=("times new 
             roman",16,"bold"),bg=bg_color,fg="lightgreen")
            it1_lbl.grid(row=0,column=0,padx=10,pady=10,sticky="w")
            cmb_quest1 = ttk.Combobox(F2,font=("Times new 
            roman",12),state="readonly",justify="center",width=5)
            cmb_quest1['values'] = ("0","1","2")
            cmb_quest1.grid(column=1,padx=10,pady=0,row=0)
            cmb_quest1.current(0)
            it1_lbl_txt = Entry(F2,width=3,font=("Times new 
            roman",15,"bold"),bd=5,relief=SUNKEN,justify="center") #textvariable=self.it1,
            it1_lbl_txt.grid(row=0,column=2,padx=10,pady=10)
    
          
    root = Tk()
    obj = Bill(root)
    root.mainloop()

``````````

---Error---
  Traceback (most recent call last):
  File "d:\Billing Software\temp.py", line 73, in <module>
    obj = Bill(root)
  File "d:\Billing Software\temp.py", line 46, in __init__
    self.fr = Frame(F2,yscrollcommand=scroll_y.set) 
  File "C:\Python\Python38\lib\tkinter\__init__.py", line 3119, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Python\Python38\lib\tkinter\__init__.py", line 2567, in __init__
    self.tk.call(
  _tkinter.TclError: unknown option "-yscrollcommand"

【问题讨论】:

  • 框架不可滚动。如果您阅读 Frame 小部件的文档,您会看到它确认了错误消息:frame don't have a yscrollcommand option。

标签: python tkinter


【解决方案1】:

不幸的是,我们无法在 Tkinter 中将滚动条添加到框架中,我们必须为此使用画布

请参考:tkinter: using scrollbars on a canvas

【讨论】:

    猜你喜欢
    • 2018-03-29
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 2012-08-12
    相关资源
    最近更新 更多