Delete Radiobuttons from running Tkinter GUI











up vote
0
down vote

favorite












I'm trying to delete the radiobuttons from my GUI using a Clear button. I found this example: enter link description here I know that I have to create a reference list for the Radionbutttons when creating them with a loop. And I can remove a button with grid_remove(). The point where I'm failing is to create the reference list. I'm getting a IndentationError: unexpected indent when i enter master.buttons.grid(column=val, row=2) into the Loop. This is my reduced code example:



import Tkinter as tk
master = tk.Tk()
var_step = IntVar()
step_mgl=session.odbs[path].steps.keys() #Imports the names of the steps from a file

i=0
steps=
while i < len(step_mgl):
steps.append((step_mgl[i], i+1))
i+=1

def clear():
for button in master.buttons:
button.grid_remove()
del master.buttons

master.buttons=
for txt, val in steps:
master.buttons.append(Radiobutton(master,
text=txt,
variable=var_step,
command=update,
value=val))
master.buttons.grid(column=val, row=2)

Button(master,text='Clear',command=clear).grid(row=3)

mainloop()


I tried so many things but i can't get this fixed, it's always the same Error. Thank you guys.



enter image description here










share|improve this question
























  • Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
    – stovfl
    yesterday










  • I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
    – TimWo
    15 hours ago










  • Read Lines and Indentation
    – stovfl
    14 hours ago















up vote
0
down vote

favorite












I'm trying to delete the radiobuttons from my GUI using a Clear button. I found this example: enter link description here I know that I have to create a reference list for the Radionbutttons when creating them with a loop. And I can remove a button with grid_remove(). The point where I'm failing is to create the reference list. I'm getting a IndentationError: unexpected indent when i enter master.buttons.grid(column=val, row=2) into the Loop. This is my reduced code example:



import Tkinter as tk
master = tk.Tk()
var_step = IntVar()
step_mgl=session.odbs[path].steps.keys() #Imports the names of the steps from a file

i=0
steps=
while i < len(step_mgl):
steps.append((step_mgl[i], i+1))
i+=1

def clear():
for button in master.buttons:
button.grid_remove()
del master.buttons

master.buttons=
for txt, val in steps:
master.buttons.append(Radiobutton(master,
text=txt,
variable=var_step,
command=update,
value=val))
master.buttons.grid(column=val, row=2)

Button(master,text='Clear',command=clear).grid(row=3)

mainloop()


I tried so many things but i can't get this fixed, it's always the same Error. Thank you guys.



enter image description here










share|improve this question
























  • Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
    – stovfl
    yesterday










  • I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
    – TimWo
    15 hours ago










  • Read Lines and Indentation
    – stovfl
    14 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to delete the radiobuttons from my GUI using a Clear button. I found this example: enter link description here I know that I have to create a reference list for the Radionbutttons when creating them with a loop. And I can remove a button with grid_remove(). The point where I'm failing is to create the reference list. I'm getting a IndentationError: unexpected indent when i enter master.buttons.grid(column=val, row=2) into the Loop. This is my reduced code example:



import Tkinter as tk
master = tk.Tk()
var_step = IntVar()
step_mgl=session.odbs[path].steps.keys() #Imports the names of the steps from a file

i=0
steps=
while i < len(step_mgl):
steps.append((step_mgl[i], i+1))
i+=1

def clear():
for button in master.buttons:
button.grid_remove()
del master.buttons

master.buttons=
for txt, val in steps:
master.buttons.append(Radiobutton(master,
text=txt,
variable=var_step,
command=update,
value=val))
master.buttons.grid(column=val, row=2)

Button(master,text='Clear',command=clear).grid(row=3)

mainloop()


I tried so many things but i can't get this fixed, it's always the same Error. Thank you guys.



enter image description here










share|improve this question















I'm trying to delete the radiobuttons from my GUI using a Clear button. I found this example: enter link description here I know that I have to create a reference list for the Radionbutttons when creating them with a loop. And I can remove a button with grid_remove(). The point where I'm failing is to create the reference list. I'm getting a IndentationError: unexpected indent when i enter master.buttons.grid(column=val, row=2) into the Loop. This is my reduced code example:



import Tkinter as tk
master = tk.Tk()
var_step = IntVar()
step_mgl=session.odbs[path].steps.keys() #Imports the names of the steps from a file

i=0
steps=
while i < len(step_mgl):
steps.append((step_mgl[i], i+1))
i+=1

def clear():
for button in master.buttons:
button.grid_remove()
del master.buttons

master.buttons=
for txt, val in steps:
master.buttons.append(Radiobutton(master,
text=txt,
variable=var_step,
command=update,
value=val))
master.buttons.grid(column=val, row=2)

Button(master,text='Clear',command=clear).grid(row=3)

mainloop()


I tried so many things but i can't get this fixed, it's always the same Error. Thank you guys.



enter image description here







python tkinter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 hours ago

























asked yesterday









TimWo

83




83












  • Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
    – stovfl
    yesterday










  • I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
    – TimWo
    15 hours ago










  • Read Lines and Indentation
    – stovfl
    14 hours ago


















  • Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
    – stovfl
    yesterday










  • I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
    – TimWo
    15 hours ago










  • Read Lines and Indentation
    – stovfl
    14 hours ago
















Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
– stovfl
yesterday




Your code gives AttributeError: 'list' object has no attribute 'grid'. Replace with master.buttons[-1].grid(column=val, row=2)
– stovfl
yesterday












I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
– TimWo
15 hours ago




I tried your option but i still gives me the same error. I added a screenshot of the error at the end of my post.
– TimWo
15 hours ago












Read Lines and Indentation
– stovfl
14 hours ago




Read Lines and Indentation
– stovfl
14 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371682%2fdelete-radiobuttons-from-running-tkinter-gui%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371682%2fdelete-radiobuttons-from-running-tkinter-gui%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Cypress Hill

what are some tips for doing well in the interview? [on hold]

How does a super-power salesman not get shut down for legal reasons?