Reputation: 1
Lets see if i can make my self understandable .
this creates multiple menus and it gets the values to populate it on a txt, the issue here is that it always assume the last request_box textbox, if i click on option 1 he will populate the last request_box that is inside option3
this call is made like this
makesubmenu("something",tab1)
makesubmenu("something1",tab2)
makesubmenu("something2",tab3)
.
def makesubmenu(tipo_de_conf, framename):
frmbut = ttk.Frame(framename)
frmbut.pack(side="top", anchor='nw')
global lsttiporeq, lsttitreq, lstjsonreq, lstexpectresq, request_box
varconfbook = open("menu_dumps.txt", "r").readlines()
lsttiporeq = []
lsttitreq = []
lstjsonreq = []
lstexpectresq = []
cont = 0
for line in varconfbook:
if tipo_de_conf in line:
tiporeq, titreq, jsonreq, expectresq = line.split('<->')
lsttiporeq.append(tiporeq)
lsttitreq.append(titreq)
lstjsonreq.append(jsonreq)
lstexpectresq.append(expectresq)
ttk.Button(frmbut, width="20", text=titreq, command=lambda cont=cont: ChangConfWI(int(cont))).grid(column=0, row=cont, padx=10, pady=10)
cont += 1
frmtxtb2 = ttk.Frame(framename)
frmtxtb2.pack(side="right", anchor='ne')
ttk.Label(frmtxtb2, text="Response:").grid(column=4, row=1, padx=10, pady=10)
request_box = ScrolledText(frmtxtb2, width=75, height=10, wrap=tk.WORD)
request_box.grid(column=4, row=2, padx=10, pady=10, ipady=35)
return lsttiporeq, lsttitreq, lstjsonreq, lstexpectresq, request_box
def ChangConfWI(tipreq):
global expResp, payload, headers, timeoutvar, tiporeq
payload = lstjsonreq[tipreq]
request_box.delete('1.0', END)
request_box.insert(tk.INSERT, payload)
return expResp, payload, headers, timeoutvar, tiporeq,request_box
txt example:
something <-> without inputs <-> {} <-> Response retrieving no
something1 <-> inputs <-> {} <-> Response retrieving
something1 <-> without inputs <-> {} <-> Response retrieving no
something2 <-> inputs <-> {} <-> Response retrieving
something2 <-> without inputs <-> {} <-> Response retrieving no
I need it to make the insert in its specific option.
thanks
Upvotes: 0
Views: 36
Reputation: 385800
Arguably, the best solution is to use a class to represent each tab, so that the class instance can hold a reference to its text widget.
Since you aren't using classes, you can pass the text widget to your ChangeConWI
function. That requires that you make the widget before you create the buttons.
def makesubmenu(tipo_de_conf, framename):
...
request_box = ScrolledText(frmtxtb2, width=75, height=10, wrap=tk.WORD)
for line in varconfbook:
if tipo_de_conf in line:
...
ttk.Button(..., command=lambda cont=cont text=request_box: ChangConfWI(text, cont))
...
def ChangConfWI(text, tipreq):
...
text.delete('1.0', END)
text.insert(tk.INSERT, payload)
Upvotes: 1