How do you get a different value for a label each time a button is pressed in `tkinter`?
So I'm making a random name generator. Everything is pretty much finished in my GUI. The problem is I can only press my generate button once to get all the values that are needed. How can I press the button infinite amount of times, getting different values each time the button is pressed.
Do I need to make a loop of some sort? I put a lambda
in there. That holds back the values from just showing on my screen as soon as you open the GUI. This way you can press the button and text appears like normal.
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name)
fullnameentry = Entry(MyWin, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
fullnameentry.config(text=estr)
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command= lambda: buttonfunc())
python button tkinter command
add a comment |
So I'm making a random name generator. Everything is pretty much finished in my GUI. The problem is I can only press my generate button once to get all the values that are needed. How can I press the button infinite amount of times, getting different values each time the button is pressed.
Do I need to make a loop of some sort? I put a lambda
in there. That holds back the values from just showing on my screen as soon as you open the GUI. This way you can press the button and text appears like normal.
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name)
fullnameentry = Entry(MyWin, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
fullnameentry.config(text=estr)
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command= lambda: buttonfunc())
python button tkinter command
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy i usedfrom tkinter import *
So does it matter how I import tkinter?. I am aware that*
means everything. So it wouldn't only make sense to import evrything from thetkinter
package?
– chrisT4
Jan 5 at 18:40
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46
add a comment |
So I'm making a random name generator. Everything is pretty much finished in my GUI. The problem is I can only press my generate button once to get all the values that are needed. How can I press the button infinite amount of times, getting different values each time the button is pressed.
Do I need to make a loop of some sort? I put a lambda
in there. That holds back the values from just showing on my screen as soon as you open the GUI. This way you can press the button and text appears like normal.
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name)
fullnameentry = Entry(MyWin, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
fullnameentry.config(text=estr)
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command= lambda: buttonfunc())
python button tkinter command
So I'm making a random name generator. Everything is pretty much finished in my GUI. The problem is I can only press my generate button once to get all the values that are needed. How can I press the button infinite amount of times, getting different values each time the button is pressed.
Do I need to make a loop of some sort? I put a lambda
in there. That holds back the values from just showing on my screen as soon as you open the GUI. This way you can press the button and text appears like normal.
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name)
fullnameentry = Entry(MyWin, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
fullnameentry.config(text=estr)
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command= lambda: buttonfunc())
python button tkinter command
python button tkinter command
edited Dec 31 '18 at 17:08
finefoot
2,74031834
2,74031834
asked Dec 31 '18 at 16:50
chrisT4chrisT4
286
286
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy i usedfrom tkinter import *
So does it matter how I import tkinter?. I am aware that*
means everything. So it wouldn't only make sense to import evrything from thetkinter
package?
– chrisT4
Jan 5 at 18:40
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46
add a comment |
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy i usedfrom tkinter import *
So does it matter how I import tkinter?. I am aware that*
means everything. So it wouldn't only make sense to import evrything from thetkinter
package?
– chrisT4
Jan 5 at 18:40
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy i used
from tkinter import *
So does it matter how I import tkinter?. I am aware that *
means everything. So it wouldn't only make sense to import evrything from the tkinter
package?– chrisT4
Jan 5 at 18:40
@Jayjayyy i used
from tkinter import *
So does it matter how I import tkinter?. I am aware that *
means everything. So it wouldn't only make sense to import evrything from the tkinter
package?– chrisT4
Jan 5 at 18:40
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46
add a comment |
1 Answer
1
active
oldest
votes
You generate the random name only once. From then on estr
is always going to be the same value.
If you're comfortable with lambda
you can use that to make full_name
into a function:
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
Afterwards, you'll have to call full_name
since it's not a simple string variable anymore but a function:
estr.set(full_name())
Also, you seem to miss setting textvariable=estr
for fullnameentry
.
Everything put together:
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name())
fullnameentry = Entry(MyWin, textvariable=estr, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
estr.set(full_name())
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command=buttonfunc)
I also think your code might be a little bit too complicated at some points. Here is a minimal and complete tkinter
example, maybe this will help you in some way:
import tkinter as tk
import random
def random_name():
first_names = ['Chris', 'Kevin', 'Jeff', 'Marty', 'Dolen']
last_names = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = '{} {}'.format(random.choice(first_names), random.choice(last_names))
return full_name
def update_label_and_entry():
new_random_name = random_name()
label.config(text=new_random_name)
entry.delete(0, tk.END) # delete content from 0 to end
entry.insert(0, new_random_name) # insert new_random_name at position 0
root = tk.Tk()
label = tk.Label(root)
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="New random name", command=update_label_and_entry)
button.pack()
root.mainloop()
Of course, this code is not perfect. The code could be improved further for example by moving first_names
and last_names
to a global namespace, so other methods can access the values, too. Also, you could write a class for your window or for the label which will include the update_label
method.
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
|
show 5 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%2f53989666%2fhow-do-you-get-a-different-value-for-a-label-each-time-a-button-is-pressed-in-t%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
You generate the random name only once. From then on estr
is always going to be the same value.
If you're comfortable with lambda
you can use that to make full_name
into a function:
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
Afterwards, you'll have to call full_name
since it's not a simple string variable anymore but a function:
estr.set(full_name())
Also, you seem to miss setting textvariable=estr
for fullnameentry
.
Everything put together:
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name())
fullnameentry = Entry(MyWin, textvariable=estr, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
estr.set(full_name())
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command=buttonfunc)
I also think your code might be a little bit too complicated at some points. Here is a minimal and complete tkinter
example, maybe this will help you in some way:
import tkinter as tk
import random
def random_name():
first_names = ['Chris', 'Kevin', 'Jeff', 'Marty', 'Dolen']
last_names = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = '{} {}'.format(random.choice(first_names), random.choice(last_names))
return full_name
def update_label_and_entry():
new_random_name = random_name()
label.config(text=new_random_name)
entry.delete(0, tk.END) # delete content from 0 to end
entry.insert(0, new_random_name) # insert new_random_name at position 0
root = tk.Tk()
label = tk.Label(root)
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="New random name", command=update_label_and_entry)
button.pack()
root.mainloop()
Of course, this code is not perfect. The code could be improved further for example by moving first_names
and last_names
to a global namespace, so other methods can access the values, too. Also, you could write a class for your window or for the label which will include the update_label
method.
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
|
show 5 more comments
You generate the random name only once. From then on estr
is always going to be the same value.
If you're comfortable with lambda
you can use that to make full_name
into a function:
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
Afterwards, you'll have to call full_name
since it's not a simple string variable anymore but a function:
estr.set(full_name())
Also, you seem to miss setting textvariable=estr
for fullnameentry
.
Everything put together:
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name())
fullnameentry = Entry(MyWin, textvariable=estr, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
estr.set(full_name())
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command=buttonfunc)
I also think your code might be a little bit too complicated at some points. Here is a minimal and complete tkinter
example, maybe this will help you in some way:
import tkinter as tk
import random
def random_name():
first_names = ['Chris', 'Kevin', 'Jeff', 'Marty', 'Dolen']
last_names = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = '{} {}'.format(random.choice(first_names), random.choice(last_names))
return full_name
def update_label_and_entry():
new_random_name = random_name()
label.config(text=new_random_name)
entry.delete(0, tk.END) # delete content from 0 to end
entry.insert(0, new_random_name) # insert new_random_name at position 0
root = tk.Tk()
label = tk.Label(root)
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="New random name", command=update_label_and_entry)
button.pack()
root.mainloop()
Of course, this code is not perfect. The code could be improved further for example by moving first_names
and last_names
to a global namespace, so other methods can access the values, too. Also, you could write a class for your window or for the label which will include the update_label
method.
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
|
show 5 more comments
You generate the random name only once. From then on estr
is always going to be the same value.
If you're comfortable with lambda
you can use that to make full_name
into a function:
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
Afterwards, you'll have to call full_name
since it's not a simple string variable anymore but a function:
estr.set(full_name())
Also, you seem to miss setting textvariable=estr
for fullnameentry
.
Everything put together:
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name())
fullnameentry = Entry(MyWin, textvariable=estr, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
estr.set(full_name())
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command=buttonfunc)
I also think your code might be a little bit too complicated at some points. Here is a minimal and complete tkinter
example, maybe this will help you in some way:
import tkinter as tk
import random
def random_name():
first_names = ['Chris', 'Kevin', 'Jeff', 'Marty', 'Dolen']
last_names = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = '{} {}'.format(random.choice(first_names), random.choice(last_names))
return full_name
def update_label_and_entry():
new_random_name = random_name()
label.config(text=new_random_name)
entry.delete(0, tk.END) # delete content from 0 to end
entry.insert(0, new_random_name) # insert new_random_name at position 0
root = tk.Tk()
label = tk.Label(root)
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="New random name", command=update_label_and_entry)
button.pack()
root.mainloop()
Of course, this code is not perfect. The code could be improved further for example by moving first_names
and last_names
to a global namespace, so other methods can access the values, too. Also, you could write a class for your window or for the label which will include the update_label
method.
You generate the random name only once. From then on estr
is always going to be the same value.
If you're comfortable with lambda
you can use that to make full_name
into a function:
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
Afterwards, you'll have to call full_name
since it's not a simple string variable anymore but a function:
estr.set(full_name())
Also, you seem to miss setting textvariable=estr
for fullnameentry
.
Everything put together:
firstnameli = ['Chris ', 'Kevin ', 'Jeff ', 'Marty ', 'Dolen ']
lastnameli = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = lambda: random.choice(firstnameli) + random.choice(lastnameli)
#this allows text to be put in the text box
estr = StringVar()
estr.set(full_name())
fullnameentry = Entry(MyWin, textvariable=estr, borderwidth=5, font=("Helvetica", 15))
def buttonfunc():
estr.set(full_name())
genbutton = Button(MyWin, text="GENERATE", activebackground="blue", command=buttonfunc)
I also think your code might be a little bit too complicated at some points. Here is a minimal and complete tkinter
example, maybe this will help you in some way:
import tkinter as tk
import random
def random_name():
first_names = ['Chris', 'Kevin', 'Jeff', 'Marty', 'Dolen']
last_names = ['Smith', 'Miller', 'Jones', 'Davis', 'Brown']
full_name = '{} {}'.format(random.choice(first_names), random.choice(last_names))
return full_name
def update_label_and_entry():
new_random_name = random_name()
label.config(text=new_random_name)
entry.delete(0, tk.END) # delete content from 0 to end
entry.insert(0, new_random_name) # insert new_random_name at position 0
root = tk.Tk()
label = tk.Label(root)
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="New random name", command=update_label_and_entry)
button.pack()
root.mainloop()
Of course, this code is not perfect. The code could be improved further for example by moving first_names
and last_names
to a global namespace, so other methods can access the values, too. Also, you could write a class for your window or for the label which will include the update_label
method.
edited Jan 4 at 12:48
answered Dec 31 '18 at 16:53
finefootfinefoot
2,74031834
2,74031834
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
|
show 5 more comments
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
I think you should store the list outside of the function in the global namespace.
– Mike - SMT
Dec 31 '18 at 17:13
1
1
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
Yes. The reason I think its best that those list are outside of the function is so they can be accessed by any code that might need them later in development. For updating names or other random generators. From a ease of use standpoint I usually place list like these in the global.
– Mike - SMT
Dec 31 '18 at 17:24
1
1
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Yes I do agree that a class is the best solution as to avoid the global namespace being one of the biggest advantages. In any case. Thanks for adding that info into your answer.
– Mike - SMT
Dec 31 '18 at 17:38
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
Thank you so much guys. Your code is way more organized. But it still isn't working. I still need to use a lambda expression on the button command so the text doesn't show when I open my GUI. I still can't press the button an infinte number of times. Only once.
– chrisT4
Dec 31 '18 at 17:42
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
@Jayjayy Yes, that is exactly what I want. Hence, the generate button. If I dont put a lambda expression on the button command like in my first example, the text just sits there. The button has no function at all. Pretty much nothing happens
– chrisT4
Dec 31 '18 at 17:51
|
show 5 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%2f53989666%2fhow-do-you-get-a-different-value-for-a-label-each-time-a-button-is-pressed-in-t%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
@Jayjayyy thanks for letting me know. I have one more question. Is there anyway you can explain how using .tk puts the text in the Entry box? The way I imported tkinter was from tkinter import * . Does that have anything to do with it? (Please forgive. I dont know how to use code tags.)
– chrisT4
Jan 4 at 4:57
@Jayjayyy i used
from tkinter import *
So does it matter how I import tkinter?. I am aware that*
means everything. So it wouldn't only make sense to import evrything from thetkinter
package?– chrisT4
Jan 5 at 18:40
@Jayjayyy Ok thanks for your help.
– chrisT4
Jan 5 at 18:46