1. <tfoot id='wNgne'></tfoot>

      <small id='wNgne'></small><noframes id='wNgne'>

        <bdo id='wNgne'></bdo><ul id='wNgne'></ul>
    2. <i id='wNgne'><tr id='wNgne'><dt id='wNgne'><q id='wNgne'><span id='wNgne'><b id='wNgne'><form id='wNgne'><ins id='wNgne'></ins><ul id='wNgne'></ul><sub id='wNgne'></sub></form><legend id='wNgne'></legend><bdo id='wNgne'><pre id='wNgne'><center id='wNgne'></center></pre></bdo></b><th id='wNgne'></th></span></q></dt></tr></i><div id='wNgne'><tfoot id='wNgne'></tfoot><dl id='wNgne'><fieldset id='wNgne'></fieldset></dl></div>

      1. <legend id='wNgne'><style id='wNgne'><dir id='wNgne'><q id='wNgne'></q></dir></style></legend>

        如何将对话框窗口中的选定文件添加到字典中?

        时间:2023-10-08
      2. <tfoot id='TrJEz'></tfoot>

          <small id='TrJEz'></small><noframes id='TrJEz'>

          <i id='TrJEz'><tr id='TrJEz'><dt id='TrJEz'><q id='TrJEz'><span id='TrJEz'><b id='TrJEz'><form id='TrJEz'><ins id='TrJEz'></ins><ul id='TrJEz'></ul><sub id='TrJEz'></sub></form><legend id='TrJEz'></legend><bdo id='TrJEz'><pre id='TrJEz'><center id='TrJEz'></center></pre></bdo></b><th id='TrJEz'></th></span></q></dt></tr></i><div id='TrJEz'><tfoot id='TrJEz'></tfoot><dl id='TrJEz'><fieldset id='TrJEz'></fieldset></dl></div>
            <tbody id='TrJEz'></tbody>

          <legend id='TrJEz'><style id='TrJEz'><dir id='TrJEz'><q id='TrJEz'></q></dir></style></legend>

                • <bdo id='TrJEz'></bdo><ul id='TrJEz'></ul>
                  本文介绍了如何将对话框窗口中的选定文件添加到字典中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我希望它能够打开一个对话窗口并选择我的文件,

                  I wish it's able to open a dialog window and select my files,

                  a.txt
                  b.txt
                  

                  然后将它们添加到我的字典中

                  then add them in my dictionary

                  myDict = { "a.txt" : 0,
                             "b.txt" : 1}
                  

                  我在网站上搜索过

                  import Tkinter,tkFileDialog
                  root = Tkinter.Tk()
                  filez = tkFileDialog.askopenfilenames(parent=root,multiple='multiple',title='Choose a file')
                  

                  这些代码用于打开对话窗口并选择我的文件.但问题是如何将选中的文件添加到字典中?

                  these codes work for opening a dialog window and selecting my files. But the question is how to add the selected files to the dictionary?

                  有了斯蒂芬的回答,问题就解决了

                  With Stephan's answer, the problem is solved

                  myDict = {}
                  for filename in filez:
                      myDict[filename] = len(myDict)
                      print "myDict: " + str(myDict)
                  

                  现在 myDict 是

                  Now the myDict is

                  myDict = {'C:/a.txt': 0}
                  myDict = {'C:/a.txt': 0, 'C:/b.txt': 1}
                  

                  网上搜索后,添加os.path.split

                  After searching online, just add os.path.split

                  myDict = {}
                  for filename in filez:
                      head, tail = os.path.split(str(filename))
                      myDict[tail] = len(myDict)
                  

                  现在一切正常

                  myDict = {'a.txt': 0, 'b.txt': 1}
                  

                  我得到了没有路径的 myDict,问题解决了!谢谢!

                  I got the myDict without path, problem solved! Thanks!

                  推荐答案

                  myDict = {}
                  myDict[filenameFromDialog] = len(myDict)
                  

                  这是添加到字典的语法.

                  That is the syntax for adding to a dictionary.

                  如果您有一组文件要添加到字典中,您可以遍历列表并一次添加一个:

                  If you have an array of files you want to add to the dictionary, you could loop over the list and add them one at a time:

                  myDict = {}
                  for filename in filez:
                      myDict[filename] = len(myDict)
                  

                  这篇关于如何将对话框窗口中的选定文件添加到字典中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何显示 PyQt 模式对话框并在关闭后从其控件中 下一篇:在 PyQt 中打开第二个窗口

                  相关文章

                  最新文章

                • <i id='mN0IA'><tr id='mN0IA'><dt id='mN0IA'><q id='mN0IA'><span id='mN0IA'><b id='mN0IA'><form id='mN0IA'><ins id='mN0IA'></ins><ul id='mN0IA'></ul><sub id='mN0IA'></sub></form><legend id='mN0IA'></legend><bdo id='mN0IA'><pre id='mN0IA'><center id='mN0IA'></center></pre></bdo></b><th id='mN0IA'></th></span></q></dt></tr></i><div id='mN0IA'><tfoot id='mN0IA'></tfoot><dl id='mN0IA'><fieldset id='mN0IA'></fieldset></dl></div>

                  1. <tfoot id='mN0IA'></tfoot>

                    1. <legend id='mN0IA'><style id='mN0IA'><dir id='mN0IA'><q id='mN0IA'></q></dir></style></legend>
                        <bdo id='mN0IA'></bdo><ul id='mN0IA'></ul>

                      <small id='mN0IA'></small><noframes id='mN0IA'>