【发布时间】:2015-07-01 01:07:45
【问题描述】:
下面的 python gui 代码我试图从下拉菜单按钮(图形和密度)中选择值,并尝试将它们作为命令行参数传递给 readfile() 函数中的 os.system 命令,如下所示,但是我在将我从下拉菜单中选择的值传递给 os.system 命令时遇到问题。
导入操作系统 将 Tkinter 导入为 tk
def buttonClicked(btn):
density= btn
def graphselected(graphbtn):
graph=graphbtn
def readfile():
os.system( 'python C:Desktop/python/ABC.py graph density')
root = tk.Tk()
root.title("Dense Module Enumeration")
btnList=[0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
btnMenu = tk.Menubutton(root, text='Density')
contentMenu = tk.Menu(btnMenu)
btnMenu.config(menu=contentMenu)
for btn in btnList:
contentMenu.add_command(label=btn, command = lambda btn=btn: buttonClicked(btn))
btnMenu.pack()
graph_list=['graph1.txt','graph2.txt','graph3.txt','graph.txt']
btnMenu = tk.Menubutton(root, text='graph')
contentMenu = tk.Menu(btnMenu)
btnMenu.config(menu=contentMenu)
for btn in graph_list:
contentMenu.add_command(label=btn, command =lambda btn= btn: graphselected(btn))
btnMenu.pack()
button = tk.Button(root, text="DME", command=readfile)
button.pack()
root.mainloop()
【问题讨论】:
标签: python python-2.7 tkinter subprocess