亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

下拉菜單給出 txt 文件中的 PY_VAR0

下拉菜單給出 txt 文件中的 PY_VAR0

MYYA 2023-08-08 17:46:03
我正在為我的朋友開發一個小項目,它是使用 python tkinter 進行的。代碼是def run():    filename = filename_ent.get()    if filename == '':        # to show an error that boxes are empty        messagebox.showerror(            'File exists', 'File already exists, try some other name thas is not used before')    if os.path.exists(f'{filename}.txt'):        # to show an error if the file already exists        messagebox.showerror(            'File exists', 'File already exists, try some other name not used before')    else:        # to open the file for python        new = open(f'{filename}.txt', '+w', encoding='utf-8')        # to write the name and email inside the file        new.write(f'''Day of the week: {clicked}''')        eventl.config(text=f'Done :)!')  # to change the label to the name        os.startfile(f'{filename}.txt')  # to open the file in a new windoweventl = Label(root, text='What is the name of the event',font=('helvatica',14))eventl.place(x=0,y=0)lfilename = Label(root,text="What do you want to call the file?", font = ("helvatica, 14"))lfilename.pack()filename_ent = Entry(root)filename_ent.pack(pady=10,padx=30)clicked = StringVar()drop = OptionMenu(root, clicked, "Monday", "Tuesday")        drop.pack(pady=10,padx=10)b = Button(root, text='Done', command=run)b.pack(pady=(10, 0))root.mainloop()注意:我使用 utf-8 因為我也使用阿拉伯輸入,但這似乎不是問題,因為我嘗試刪除它(這不是完整的代碼)。
查看完整描述

1 回答

?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

它應該new.write(f'''Day of the week: {clicked.get()}''')代替new.write(f'''Day of the week: {clicked}''')StringVar()單擊是您必須使用該方法訪問它的值的唯一方法get()

希望這有幫助,如果有任何錯誤請告訴我。

干杯


查看完整回答
反對 回復 2023-08-08
  • 1 回答
  • 0 關注
  • 452 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號