Tkinter: Create an arbitrary amount of buttons










0















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)










share|improve this question
























  • 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















0















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)










share|improve this question
























  • 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













0












0








0








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)










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer

























  • 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












  • @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











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
);



);













draft saved

draft discarded


















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









1














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.






share|improve this answer

























  • 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












  • @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
















1














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.






share|improve this answer

























  • 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












  • @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














1












1








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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. 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












  • @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











  • 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


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto