python tkinter图片为什么要设置全局变量_python-3.x - 定义使用Tkinter的使用进行分析文件的列表。有一个很难访问全局变量。 (Python 3中) - SO中文参考 - ...

我希望一切都好。相当新的编程,所以请多多包涵。

我正在使用的Tkinter会提示我选择一组将被用来执行一些分析文件的GUI。我希望将这些文件保存在我以后可以参考清单。有两个必需的文件,一个DBC文件和ASC文件。什么我有问题是能够引用文件(S)我所定义的功能之外。我试图将其定义为一个全局变量(我已阅读是不可取的,因为它可以导致在道路上的问题)。我得到一个错误说DBFILES或ascfiles时,只是想打印没有定义。下面是我到目前为止写的:

import tkinter as tk

from tkinter import messagebox

from tkinter import filedialog

root = tk.Tk()

root.geometry("500x700")

def dbbutton():

dbfiles = filedialog.askopenfilenames(parent=root, title='Select .DBC File(s)')

dbfiles = root.tk.splitlist(dbfiles)

for file1 in dbfiles:

L1.insert(tk.END, file1)

return dbfiles

def ascbutton():

ascfiles = filedialog.askopenfilenames(parent=root, title='Select .ASC File(s)')

ascfiles = root.tk.splitlist(ascfiles)

for file2 in ascfiles:

L2.insert(tk.END, file2)

return ascfiles

b1 = tk.Button (root, text= "Select Database File(s)", command = dbbutton)

b1.pack()

L1 = tk.Listbox(root, selectmode = "multiple", height = 10, width = 80)

L1.pack()

b2 = tk.Button (root, text = "Select ASC File(s)", command = ascbutton)

b2.pack()

L2 = tk.Listbox(root, selectmode = "multiple", height = 10, width = 80 )

L2.pack()

root.mainloop()

什么是我引用的功能外,这些文件的最有效的方法是什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值