Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 图形用户界面错误_Python_User Interface_Tkinter - Fatal编程技术网

Python 图形用户界面错误

Python 图形用户界面错误,python,user-interface,tkinter,Python,User Interface,Tkinter,我的保存文件程序有点问题。。当我运行它时,会出现一个错误,它说“桌面本地化不可用”。我的代码或笔记本电脑是否有问题? 这是我的密码: # -*- coding: utf-8 -*- import Tkinter as T, tkFileDialog import os from time import gmtime, strftime import serial class Program(T.Frame): def __init__(self, root):

我的保存文件程序有点问题。。当我运行它时,会出现一个错误,它说“桌面本地化不可用”。我的代码或笔记本电脑是否有问题? 这是我的密码:

# -*- coding: utf-8 -*-

import Tkinter as T,  tkFileDialog
import os
from time import gmtime, strftime
import serial

class Program(T.Frame):

    def __init__(self, root):

        T.Frame.__init__(self, root)
        T.Label(self, text = 'Better do that man').pack()
        T.Button(self, text='Save Me!', command=self.save).pack()


        self.fileop = options = {}
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt'),('dat files','.dat')]
        options['initialfile'] = 'myfile.txt'
        options['parent'] = root
        options['initialdir'] = 'C:\Users\Michał\Desktop'

    def save(self):
        filename = tkFileDialog.asksaveasfilename(**self.fileop)
        root.destroy()

        if filename:
            file = open(filename, 'a')
            time = strftime("%A, %d %b %Y, %H:%M:%S ", gmtime())
            file.write(time)
            file.write('\n')
            entry = raw_input('Treść: \n')
            file.write(entry)
            file.close()

if __name__=='__main__':
    root = T.Tk()
    Program(root).pack()
    root.mainloop()

我认为此错误意味着您正在使用的特定本地化版本的windows中没有“桌面”文件夹。这不是python或tkinter本身的错误,只是您的代码依赖于不存在的OS功能(桌面文件夹)


您可以通过简单地将初始目录更改为当前目录来解决此错误

代码对我来说没有任何错误。这可能是python配置的一些问题。