【发布时间】:2021-05-07 14:58:02
【问题描述】:
def Main_Menu():
for widget in myframe_1.winfo_children():
widget.destroy()
PostIt_Count = len([name for name in os.listdir('C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts')])
if PostIt_Count > 0:
for i in range(PostIt_Count):
PostIt_NamesList = [name for name in os.listdir('C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts')]
global selected_postit
selected_postit = tk.StringVar()
PostIt_ButtonName = ttk.Radiobutton(myframe_1, text=PostIt_NamesList[i], variable=selected_postit)
y = ([x for x in range(1, PostIt_Count +1)][i])- 0.4
if PostIt_Count < 10:
y = str(y)[:1] + str(y)[2:]
else:
y = str(y)[:2] + str(y)[3:]
yname = '.' + y
PostIt_ButtonName.place(relx=.1, rely=yname)
def Read_PostIt():
for widget in myframe_3.winfo_children():
widget.destroy()
filepath = 'C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts/'
postit = selected_postit.get()
print(postit)
f = filepath + postit
print(f)
os.chmod('C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts/', stat.S_IRWXO)
with open('{}'.format(f), 'r') as fi:
global text
text = fi.readlines()
fi.close()
text_label = Label(myframe_3, text='{}'.format(text))
text_label.place(relx=.01, rely=.01)
我正在做一个便利贴应用程序。有作为单选按钮列出的便利贴及其文件名。这个想法是,当我选择一个单选按钮并单击读取按钮时,Read_PostIt 函数将读取便利贴文件并显示文本。但是,当 selected_postit.get() 行应该返回便利贴的名称时,它不会返回任何内容。 ```print(postit)´´´ 只打印一个空行。这是为什么呢?
这是输出和回溯:
PS C:\Users\Aatu\Documents\python\pythonleikit> & C:/Python39ni/python.exe c:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/post-its.py
C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts/
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python39ni\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "c:\Users\Aatu\Documents\python\pythonleikit\tkinterstuff\PostItApp\post-its.py", line 77, in Read_PostIt
with open('{}'.format(f), 'r') as fi:
PermissionError: [Errno 13] Permission denied: 'C:/Users/Aatu/Documents/python/pythonleikit/tkinterstuff/PostItApp/PostIts/'
程序应在其目录路径的末尾添加便利贴的名称,但末尾没有任何内容。
请有人帮忙。
【问题讨论】:
-
你真的把pascal case和smake case结合起来了吗?那是不可读的
-
我们还需要最少的可重现示例