Login Button Function
I am experimenting with tkinter
in python.
At the moment I have created a script which creates a login window which has no function what so ever. I have tried playing around with the def callback():
and command=callback
. So I tried making it so that when you press the "Login" button, you can do something (e.g. show loading... and clear text boxes.)
Here is the code:
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def callback():
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000")
button.pack()
label = tkinter.Label(window, text="Loading...", bg="#FFFFFF", command=callback)
window.mainloop()
python tkinter raspberry-pi3
add a comment |
I am experimenting with tkinter
in python.
At the moment I have created a script which creates a login window which has no function what so ever. I have tried playing around with the def callback():
and command=callback
. So I tried making it so that when you press the "Login" button, you can do something (e.g. show loading... and clear text boxes.)
Here is the code:
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def callback():
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000")
button.pack()
label = tkinter.Label(window, text="Loading...", bg="#FFFFFF", command=callback)
window.mainloop()
python tkinter raspberry-pi3
So the question is - how to make a button?Also, please format the code with thecode markdown
– Urosh T.
Nov 25 '18 at 17:03
Move this.Label(..., command=callback
to the.Button(..., command=callback
and add a ` print('Hello World)'` to yourdef callback():
.
– stovfl
Nov 25 '18 at 18:20
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26
add a comment |
I am experimenting with tkinter
in python.
At the moment I have created a script which creates a login window which has no function what so ever. I have tried playing around with the def callback():
and command=callback
. So I tried making it so that when you press the "Login" button, you can do something (e.g. show loading... and clear text boxes.)
Here is the code:
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def callback():
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000")
button.pack()
label = tkinter.Label(window, text="Loading...", bg="#FFFFFF", command=callback)
window.mainloop()
python tkinter raspberry-pi3
I am experimenting with tkinter
in python.
At the moment I have created a script which creates a login window which has no function what so ever. I have tried playing around with the def callback():
and command=callback
. So I tried making it so that when you press the "Login" button, you can do something (e.g. show loading... and clear text boxes.)
Here is the code:
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def callback():
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000")
button.pack()
label = tkinter.Label(window, text="Loading...", bg="#FFFFFF", command=callback)
window.mainloop()
python tkinter raspberry-pi3
python tkinter raspberry-pi3
edited Nov 25 '18 at 22:24
not2qubit
4,45014065
4,45014065
asked Nov 25 '18 at 16:26
Deon LeggettDeon Leggett
82
82
So the question is - how to make a button?Also, please format the code with thecode markdown
– Urosh T.
Nov 25 '18 at 17:03
Move this.Label(..., command=callback
to the.Button(..., command=callback
and add a ` print('Hello World)'` to yourdef callback():
.
– stovfl
Nov 25 '18 at 18:20
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26
add a comment |
So the question is - how to make a button?Also, please format the code with thecode markdown
– Urosh T.
Nov 25 '18 at 17:03
Move this.Label(..., command=callback
to the.Button(..., command=callback
and add a ` print('Hello World)'` to yourdef callback():
.
– stovfl
Nov 25 '18 at 18:20
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26
So the question is - how to make a button?Also, please format the code with the
code markdown
– Urosh T.
Nov 25 '18 at 17:03
So the question is - how to make a button?Also, please format the code with the
code markdown
– Urosh T.
Nov 25 '18 at 17:03
Move this
.Label(..., command=callback
to the .Button(..., command=callback
and add a ` print('Hello World)'` to your def callback():
.– stovfl
Nov 25 '18 at 18:20
Move this
.Label(..., command=callback
to the .Button(..., command=callback
and add a ` print('Hello World)'` to your def callback():
.– stovfl
Nov 25 '18 at 18:20
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26
add a comment |
1 Answer
1
active
oldest
votes
1) The callback function needs to be assigned to the command option on the Button widget.
2) The two entry widgets need different variable names for access in the callback
3) The callback function needs a body of code that does something.
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry0 = tkinter.Entry(window) # Renamed entry0 to find in callback
entry0.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry1 = tkinter.Entry(window) # Renamed entry1 to differentiate from entry0
entry1.pack()
def callback():
""" Callback to process a button click. This will be called whenever the button is clicked.
As a simple example it simply prints username and password.
"""
print("Username: ", entry0.get(), " Password: ", entry1.get())
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000", command=callback)
button.pack()
window.mainloop()
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
add a comment |
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%2f53469505%2flogin-button-function%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) The callback function needs to be assigned to the command option on the Button widget.
2) The two entry widgets need different variable names for access in the callback
3) The callback function needs a body of code that does something.
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry0 = tkinter.Entry(window) # Renamed entry0 to find in callback
entry0.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry1 = tkinter.Entry(window) # Renamed entry1 to differentiate from entry0
entry1.pack()
def callback():
""" Callback to process a button click. This will be called whenever the button is clicked.
As a simple example it simply prints username and password.
"""
print("Username: ", entry0.get(), " Password: ", entry1.get())
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000", command=callback)
button.pack()
window.mainloop()
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
add a comment |
1) The callback function needs to be assigned to the command option on the Button widget.
2) The two entry widgets need different variable names for access in the callback
3) The callback function needs a body of code that does something.
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry0 = tkinter.Entry(window) # Renamed entry0 to find in callback
entry0.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry1 = tkinter.Entry(window) # Renamed entry1 to differentiate from entry0
entry1.pack()
def callback():
""" Callback to process a button click. This will be called whenever the button is clicked.
As a simple example it simply prints username and password.
"""
print("Username: ", entry0.get(), " Password: ", entry1.get())
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000", command=callback)
button.pack()
window.mainloop()
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
add a comment |
1) The callback function needs to be assigned to the command option on the Button widget.
2) The two entry widgets need different variable names for access in the callback
3) The callback function needs a body of code that does something.
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry0 = tkinter.Entry(window) # Renamed entry0 to find in callback
entry0.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry1 = tkinter.Entry(window) # Renamed entry1 to differentiate from entry0
entry1.pack()
def callback():
""" Callback to process a button click. This will be called whenever the button is clicked.
As a simple example it simply prints username and password.
"""
print("Username: ", entry0.get(), " Password: ", entry1.get())
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000", command=callback)
button.pack()
window.mainloop()
1) The callback function needs to be assigned to the command option on the Button widget.
2) The two entry widgets need different variable names for access in the callback
3) The callback function needs a body of code that does something.
import tkinter
window = tkinter.Tk()
window.title("Login")
window.geometry("250x150")
window.configure(background="#FFFFFF")
label = tkinter.Label(window, text="Please Login to continue:", bg="#FFFFFF", font=("PibotoLt", 16))
label.pack()
label = tkinter.Label(window, text="username:", bg="#FFFFFF")
label.pack()
entry0 = tkinter.Entry(window) # Renamed entry0 to find in callback
entry0.pack()
label = tkinter.Label(window, text="password:", bg="#FFFFFF")
label.pack()
entry1 = tkinter.Entry(window) # Renamed entry1 to differentiate from entry0
entry1.pack()
def callback():
""" Callback to process a button click. This will be called whenever the button is clicked.
As a simple example it simply prints username and password.
"""
print("Username: ", entry0.get(), " Password: ", entry1.get())
button = tkinter.Button(window, text="Login", fg="#FFFFFF", bg="#000000", command=callback)
button.pack()
window.mainloop()
edited Nov 25 '18 at 21:45
answered Nov 25 '18 at 18:36
Tls ChrisTls Chris
47338
47338
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
add a comment |
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
Thanks Chris for the help. I see what I had done wrong now. Deon Leggett
– Deon Leggett
Nov 30 '18 at 16:02
add a comment |
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%2f53469505%2flogin-button-function%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
So the question is - how to make a button?Also, please format the code with the
code markdown
– Urosh T.
Nov 25 '18 at 17:03
Move this
.Label(..., command=callback
to the.Button(..., command=callback
and add a ` print('Hello World)'` to yourdef callback():
.– stovfl
Nov 25 '18 at 18:20
I tried to clarify the code but I'm not 100% I got the indentation right.
– not2qubit
Nov 25 '18 at 22:26