读错误信息就能大概知道是属性分配的问题,如下test2函数内self.show这里下划线报错
class Application(Frame): # gui程序类的写法,继承Frame容器组件,tkinter专用
def __int__(self, r):
self.r = r
self.pack()
self.creatWidget()
def creatWidget(self):
Button(self, text='choose the file', command=self.test2).pack()
show = Label(self, width=40, height=3, bg='green')
show.pack()
def test2(self):
f = askopenfilename(title='上传文件', initialdir='C:/1_study/pyCharm4.3/PyCharm 2023.1/pythonProject',
filetypes=[('视频文件', '.mp4')])
self.show['text'] = f
类中各个定义的属性不能直接调用,试了一下必须要通过传参的形式才可以调用,属于私有属性,如下修改,记录一下
class Application(Frame): # gui程序类的写法,继承Frame容器组件,tkinter专用
def __int__(self, r):
self.r = r
self.pack()
self.creatWidget()
def creatWidget(self):
Button(self, text='choose the file', command=lambda :self.test2(show)).pack()
show = Label(self, width=40, height=3, bg='green')
show.pack()
def test2(self,show):
f = askopenfilename(title='上传文件', initialdir='C:/1_study/pyCharm4.3/PyCharm 2023.1/pythonProject',
filetypes=[('视频文件', '.mp4')])
show['text'] = f