Tkinter: Create an arbitrary amount of buttons
Just to get this clear before I begin.
I have the same problem as outlined in this question: Tkinter: creating an arbitrary number of buttons/widgets
but the accepted answer doesn't work for me.
This is my code:
import os
try:
from tkinter import *
except ImportError:
from Tkinter import *
from subprocess import call
root = Tk()
root.wm_attributes("-fullscreen", "true")
root.config(background = "#FFFFFF")
backIMG = PhotoImage(file="b.gif")
usbIMG = PhotoImage(file="u.gif")
usbAuswahlIMG = PhotoImage(file="ua.gif")
downloadsIMG = PhotoImage(file="d.gif")
downloadsAuswahlIMG =
PhotoImage(file="da.gif")
menuFrame = Frame(root, width=200, height=600, bg="#FFFF00")
menuFrame.grid(row=0, column=0, padx=10, pady=3)
def goBack():
#os.system('python gui.py')
root.destroy()
def selectUSB():
downloadsButton.config(image=downloadsIMG)
usbButton.config(image=usbAuswahlIMG)
def selectDownloads():
usbButton.config(image=usbIMG)
downloadsButton.config(image=downloadsAuswahlIMG)
i = 0
buttons = dict()
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
buttons[i] = Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda a=i: playDL(a).grid(row=i, column=0))
i = i + 1
print()
def playDL(index):
print (index)
usbButton = Button(menuFrame, image=usbIMG,
command=selectUSB)
usbButton.pack()
downloadsButton = Button(menuFrame, image=downloadsIMG,
command=selectDownloads)
downloadsButton.pack()
stopButton = Button(menuFrame, image=backIMG,
command=goBack)
stopButton.pack()
contentFrame = Frame(root, width=760, height=594, bg='#FFFFFF')
contentFrame.grid(row=0, column=1, padx=13, pady=3)
root.mainloop()
On the other post, one suggested, to add this code here:
buttons = dict()
for k in range(len(info)):
buttons[k] = Button(top, text=info[k], command=lambda a=k: my_function(buttons[a]))
which I've done and changed it up here and there to fit my code.
The problem is that now the buttons don't show up on the content Frame at all. It still runs though the loop but no buttons to be seen. At first I just had this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
and all the buttons did the same nothingeness, but were visible.
I started programming in python yesterday but i am quiet familiar with Java and Visual C# so I have a basic understandment of what I'm doing (sort of)
python python-3.x tkinter
add a comment |
Just to get this clear before I begin.
I have the same problem as outlined in this question: Tkinter: creating an arbitrary number of buttons/widgets
but the accepted answer doesn't work for me.
This is my code:
import os
try:
from tkinter import *
except ImportError:
from Tkinter import *
from subprocess import call
root = Tk()
root.wm_attributes("-fullscreen", "true")
root.config(background = "#FFFFFF")
backIMG = PhotoImage(file="b.gif")
usbIMG = PhotoImage(file="u.gif")
usbAuswahlIMG = PhotoImage(file="ua.gif")
downloadsIMG = PhotoImage(file="d.gif")
downloadsAuswahlIMG =
PhotoImage(file="da.gif")
menuFrame = Frame(root, width=200, height=600, bg="#FFFF00")
menuFrame.grid(row=0, column=0, padx=10, pady=3)
def goBack():
#os.system('python gui.py')
root.destroy()
def selectUSB():
downloadsButton.config(image=downloadsIMG)
usbButton.config(image=usbAuswahlIMG)
def selectDownloads():
usbButton.config(image=usbIMG)
downloadsButton.config(image=downloadsAuswahlIMG)
i = 0
buttons = dict()
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
buttons[i] = Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda a=i: playDL(a).grid(row=i, column=0))
i = i + 1
print()
def playDL(index):
print (index)
usbButton = Button(menuFrame, image=usbIMG,
command=selectUSB)
usbButton.pack()
downloadsButton = Button(menuFrame, image=downloadsIMG,
command=selectDownloads)
downloadsButton.pack()
stopButton = Button(menuFrame, image=backIMG,
command=goBack)
stopButton.pack()
contentFrame = Frame(root, width=760, height=594, bg='#FFFFFF')
contentFrame.grid(row=0, column=1, padx=13, pady=3)
root.mainloop()
On the other post, one suggested, to add this code here:
buttons = dict()
for k in range(len(info)):
buttons[k] = Button(top, text=info[k], command=lambda a=k: my_function(buttons[a]))
which I've done and changed it up here and there to fit my code.
The problem is that now the buttons don't show up on the content Frame at all. It still runs though the loop but no buttons to be seen. At first I just had this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
and all the buttons did the same nothingeness, but were visible.
I started programming in python yesterday but i am quiet familiar with Java and Visual C# so I have a basic understandment of what I'm doing (sort of)
python python-3.x tkinter
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
.grid(row=i, column=0)
is in the wrong place.
– Mike - SMT
Nov 13 '18 at 13:12
add a comment |
Just to get this clear before I begin.
I have the same problem as outlined in this question: Tkinter: creating an arbitrary number of buttons/widgets
but the accepted answer doesn't work for me.
This is my code:
import os
try:
from tkinter import *
except ImportError:
from Tkinter import *
from subprocess import call
root = Tk()
root.wm_attributes("-fullscreen", "true")
root.config(background = "#FFFFFF")
backIMG = PhotoImage(file="b.gif")
usbIMG = PhotoImage(file="u.gif")
usbAuswahlIMG = PhotoImage(file="ua.gif")
downloadsIMG = PhotoImage(file="d.gif")
downloadsAuswahlIMG =
PhotoImage(file="da.gif")
menuFrame = Frame(root, width=200, height=600, bg="#FFFF00")
menuFrame.grid(row=0, column=0, padx=10, pady=3)
def goBack():
#os.system('python gui.py')
root.destroy()
def selectUSB():
downloadsButton.config(image=downloadsIMG)
usbButton.config(image=usbAuswahlIMG)
def selectDownloads():
usbButton.config(image=usbIMG)
downloadsButton.config(image=downloadsAuswahlIMG)
i = 0
buttons = dict()
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
buttons[i] = Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda a=i: playDL(a).grid(row=i, column=0))
i = i + 1
print()
def playDL(index):
print (index)
usbButton = Button(menuFrame, image=usbIMG,
command=selectUSB)
usbButton.pack()
downloadsButton = Button(menuFrame, image=downloadsIMG,
command=selectDownloads)
downloadsButton.pack()
stopButton = Button(menuFrame, image=backIMG,
command=goBack)
stopButton.pack()
contentFrame = Frame(root, width=760, height=594, bg='#FFFFFF')
contentFrame.grid(row=0, column=1, padx=13, pady=3)
root.mainloop()
On the other post, one suggested, to add this code here:
buttons = dict()
for k in range(len(info)):
buttons[k] = Button(top, text=info[k], command=lambda a=k: my_function(buttons[a]))
which I've done and changed it up here and there to fit my code.
The problem is that now the buttons don't show up on the content Frame at all. It still runs though the loop but no buttons to be seen. At first I just had this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
and all the buttons did the same nothingeness, but were visible.
I started programming in python yesterday but i am quiet familiar with Java and Visual C# so I have a basic understandment of what I'm doing (sort of)
python python-3.x tkinter
Just to get this clear before I begin.
I have the same problem as outlined in this question: Tkinter: creating an arbitrary number of buttons/widgets
but the accepted answer doesn't work for me.
This is my code:
import os
try:
from tkinter import *
except ImportError:
from Tkinter import *
from subprocess import call
root = Tk()
root.wm_attributes("-fullscreen", "true")
root.config(background = "#FFFFFF")
backIMG = PhotoImage(file="b.gif")
usbIMG = PhotoImage(file="u.gif")
usbAuswahlIMG = PhotoImage(file="ua.gif")
downloadsIMG = PhotoImage(file="d.gif")
downloadsAuswahlIMG =
PhotoImage(file="da.gif")
menuFrame = Frame(root, width=200, height=600, bg="#FFFF00")
menuFrame.grid(row=0, column=0, padx=10, pady=3)
def goBack():
#os.system('python gui.py')
root.destroy()
def selectUSB():
downloadsButton.config(image=downloadsIMG)
usbButton.config(image=usbAuswahlIMG)
def selectDownloads():
usbButton.config(image=usbIMG)
downloadsButton.config(image=downloadsAuswahlIMG)
i = 0
buttons = dict()
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
buttons[i] = Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda a=i: playDL(a).grid(row=i, column=0))
i = i + 1
print()
def playDL(index):
print (index)
usbButton = Button(menuFrame, image=usbIMG,
command=selectUSB)
usbButton.pack()
downloadsButton = Button(menuFrame, image=downloadsIMG,
command=selectDownloads)
downloadsButton.pack()
stopButton = Button(menuFrame, image=backIMG,
command=goBack)
stopButton.pack()
contentFrame = Frame(root, width=760, height=594, bg='#FFFFFF')
contentFrame.grid(row=0, column=1, padx=13, pady=3)
root.mainloop()
On the other post, one suggested, to add this code here:
buttons = dict()
for k in range(len(info)):
buttons[k] = Button(top, text=info[k], command=lambda a=k: my_function(buttons[a]))
which I've done and changed it up here and there to fit my code.
The problem is that now the buttons don't show up on the content Frame at all. It still runs though the loop but no buttons to be seen. At first I just had this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15), command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
and all the buttons did the same nothingeness, but were visible.
I started programming in python yesterday but i am quiet familiar with Java and Visual C# so I have a basic understandment of what I'm doing (sort of)
python python-3.x tkinter
python python-3.x tkinter
edited Nov 29 '18 at 10:18
ChrisF♦
114k25215291
114k25215291
asked Nov 13 '18 at 13:04
Akarui KageAkarui Kage
31
31
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
.grid(row=i, column=0)
is in the wrong place.
– Mike - SMT
Nov 13 '18 at 13:12
add a comment |
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
.grid(row=i, column=0)
is in the wrong place.
– Mike - SMT
Nov 13 '18 at 13:12
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
.grid(row=i, column=0)
is in the wrong place.– Mike - SMT
Nov 13 '18 at 13:12
.grid(row=i, column=0)
is in the wrong place.– Mike - SMT
Nov 13 '18 at 13:12
add a comment |
1 Answer
1
active
oldest
votes
Change this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
To this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda i=i: playDL(i)).grid(row=i, column=0)
i = i + 1
You placed your grid manage inside of your lambda function instead of outside the button widget.
As tobias pointed out in the comments you need to use i=i
in your lambda in order for your values to be accurate for each button or all of them will have the last value in the loop.
This fixes part of the problem, but you still have the "lambda in a loop" issue. Uselambda i=i
to bind the current value ofi
to thei
in the lambda (instead of value that's current when the lambda is evaluated)
– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.
– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
|
show 4 more comments
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281647%2ftkinter-create-an-arbitrary-amount-of-buttons%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
To this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda i=i: playDL(i)).grid(row=i, column=0)
i = i + 1
You placed your grid manage inside of your lambda function instead of outside the button widget.
As tobias pointed out in the comments you need to use i=i
in your lambda in order for your values to be accurate for each button or all of them will have the last value in the loop.
This fixes part of the problem, but you still have the "lambda in a loop" issue. Uselambda i=i
to bind the current value ofi
to thei
in the lambda (instead of value that's current when the lambda is evaluated)
– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.
– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
|
show 4 more comments
Change this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
To this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda i=i: playDL(i)).grid(row=i, column=0)
i = i + 1
You placed your grid manage inside of your lambda function instead of outside the button widget.
As tobias pointed out in the comments you need to use i=i
in your lambda in order for your values to be accurate for each button or all of them will have the last value in the loop.
This fixes part of the problem, but you still have the "lambda in a loop" issue. Uselambda i=i
to bind the current value ofi
to thei
in the lambda (instead of value that's current when the lambda is evaluated)
– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.
– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
|
show 4 more comments
Change this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
To this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda i=i: playDL(i)).grid(row=i, column=0)
i = i + 1
You placed your grid manage inside of your lambda function instead of outside the button widget.
As tobias pointed out in the comments you need to use i=i
in your lambda in order for your values to be accurate for each button or all of them will have the last value in the loop.
Change this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda: playDL(i).grid(row=i, column=0))
i = i + 1
To this:
for file in os.listdir('/home/pi/Downloads'):
if file.endswith(".mp3") or file.endswith(".wav"):
Button(contentFrame, text=file, width=60, font=("Sans", 15),
command=lambda i=i: playDL(i)).grid(row=i, column=0)
i = i + 1
You placed your grid manage inside of your lambda function instead of outside the button widget.
As tobias pointed out in the comments you need to use i=i
in your lambda in order for your values to be accurate for each button or all of them will have the last value in the loop.
edited Nov 13 '18 at 17:11
answered Nov 13 '18 at 13:15
Mike - SMTMike - SMT
9,39921234
9,39921234
This fixes part of the problem, but you still have the "lambda in a loop" issue. Uselambda i=i
to bind the current value ofi
to thei
in the lambda (instead of value that's current when the lambda is evaluated)
– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.
– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
|
show 4 more comments
This fixes part of the problem, but you still have the "lambda in a loop" issue. Uselambda i=i
to bind the current value ofi
to thei
in the lambda (instead of value that's current when the lambda is evaluated)
– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.
– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
This fixes part of the problem, but you still have the "lambda in a loop" issue. Use
lambda i=i
to bind the current value of i
to the i
in the lambda (instead of value that's current when the lambda is evaluated)– tobias_k
Nov 13 '18 at 13:18
This fixes part of the problem, but you still have the "lambda in a loop" issue. Use
lambda i=i
to bind the current value of i
to the i
in the lambda (instead of value that's current when the lambda is evaluated)– tobias_k
Nov 13 '18 at 13:18
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
Jesus Christ how could I have missed that? >~< Thanks a lot!
– Akarui Kage
Nov 13 '18 at 13:20
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
@tobias_k thanks I will add that. I was only focused on the issue of the button not showing up but that part is important as well.
– Mike - SMT
Nov 13 '18 at 13:32
It would be better if you move the
.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.– Bryan Oakley
Nov 13 '18 at 17:03
It would be better if you move the
.grid(...)
to a separate statement. It makes the code easier to read, and reinforces a good habit.– Bryan Oakley
Nov 13 '18 at 17:03
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
@BryanOakley I normally never use variable names on widgets that will not be accessed later in the code. For me it makes the code easier to read as it lets one know that this widget is set up in a way that we do not expect to edit it later or need to pull information from it directly. I do understand the standpoint of moving the grid to a new line if you want to use a variable name to assist with readability as far as know what that widget is for. What benefit is there to moving the grid to a new line here? For me it seams like there is none.
– Mike - SMT
Nov 13 '18 at 17:10
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281647%2ftkinter-create-an-arbitrary-amount-of-buttons%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Check your parentheses.
– fhdrsdg
Nov 13 '18 at 13:09
.grid(row=i, column=0)
is in the wrong place.– Mike - SMT
Nov 13 '18 at 13:12