how to give the value selected from menu button as input to os.system in python gui -


the below python gui code trying select values drop down menu buttons(graph , density) , trying pass them command line arguments os.system command in readfile() function shown below having problem in passing values have selected drop down menu os.system command.

import os import 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)  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)  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() 

it easy implement functools.partial - apply needed value function each button. here sample:

from functools import partial import tkinter tk  btnlist = [0.0, 0.1, 0.2]  def btn_clicked(payload=none):     """just prints out given payload."""     print('me clicked. payload: {}'.format(payload))   def init_controls():     """prepares gui controls , starts mainloop"""     root = tk.tk()     menu = tk.menu(root)     root.config(menu=menu)     sample_menu = tk.menu(menu)     menu.add_cascade(label="destiny", menu=sample_menu)     btn_value in btnlist:         sample_menu.add_command(             label=btn_value,             # here trick partial             command=partial(btn_clicked, btn_value)         )     root.mainloop()   init_controls() 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -