AttributeError:“Biceps”对象没有属性“os”

2024-06-26 00:26:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用tkiner中的一个按钮打开保存的视频,但我一直收到一个错误-

AttributeError: 'Biceps' object has no attribute 'os'

这是我的密码

class Biceps(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Biceps!!!", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = tk.Button(self, text="Back to Home",
                            command=lambda: controller.show_frame(StartPage))
        button1.pack()

        button2 = tk.Button(self, text="Back to Menu",
                            command=lambda: controller.show_frame(Menu))

        button2.pack()



        rb1 = tk.Button(self, text = "Play", command=self.video).pack()

    def video(self):
         self.os.system("J:\Comp Project\Bicep.mp4")

这是错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
    return self.func(*args)
  File "D:\Comp Project\Computer Science project2 test.py", line 253, in video
    self.os.system("J:\Comp Project\Bicep.mp4")
AttributeError: 'Biceps' object has no attribute 'os'

Tags: textinselfprojectinitosvideo错误
2条回答

video方法中,self引用在Biceps类上定义video方法的类的实例。这个类没有os属性,因此会出现错误。如果您在模块中导入了os,您应该直接访问它。你知道吗

尝试:

import os

...

def video(self):
    os.system("J:\Comp Project\Bicep.mp4")

问题就在这里。你知道吗

self.os.system("J:\Comp Project\Bicep.mp4")

试试这个

def video(self):
     import os
     os.system("J:\Comp Project\Bicep.mp4")

您正在尝试调用名为osBiceps属性,在这里您应该导入os库并调用system。你知道吗

相关问题 更多 >