Auto-update label with the pressing of a tkinter button
I'm trying to create a chatbot program with CHATTERBOT MODULE and TKINTER.
It's almost ok, in fact my problem is that every button-click, the program creates me new labels, with command risposta.pack()
.
My intent is creating just one label and update it every other button-click.
How can I do it?
MY CODING:
from chatterbot import ChatBot
from tkinter import *
import time
from chatterbot.trainers import ListTrainer
bot = ChatBot(
"GUI Bot",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter='chatterbot.input.VariableInputTypeAdapter',
output_adapter='chatterbot.output.OutputAdapter',
database='../database,db',
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
with open('/home/griguols/Scrivania/chatterbot/istruzioni.txt') as istruzioni:
conversation = istruzioni.readlines()
bot.set_trainer(ListTrainer)
bot.train(conversation)
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta = Label(schermata, text=str(response.text))
risposta.pack()
schermata = Tk()
ment = StringVar()
schermata.geometry('1000x500')
schermata.title('OMERO')
titolo = Label(schermata,text='OMERO')
titolo.pack()
input = Entry(schermata,textvariable=ment)
input.pack()
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
schermata.mainloop()
python python-3.x tkinter chatterbot
add a comment |
I'm trying to create a chatbot program with CHATTERBOT MODULE and TKINTER.
It's almost ok, in fact my problem is that every button-click, the program creates me new labels, with command risposta.pack()
.
My intent is creating just one label and update it every other button-click.
How can I do it?
MY CODING:
from chatterbot import ChatBot
from tkinter import *
import time
from chatterbot.trainers import ListTrainer
bot = ChatBot(
"GUI Bot",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter='chatterbot.input.VariableInputTypeAdapter',
output_adapter='chatterbot.output.OutputAdapter',
database='../database,db',
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
with open('/home/griguols/Scrivania/chatterbot/istruzioni.txt') as istruzioni:
conversation = istruzioni.readlines()
bot.set_trainer(ListTrainer)
bot.train(conversation)
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta = Label(schermata, text=str(response.text))
risposta.pack()
schermata = Tk()
ment = StringVar()
schermata.geometry('1000x500')
schermata.title('OMERO')
titolo = Label(schermata,text='OMERO')
titolo.pack()
input = Entry(schermata,textvariable=ment)
input.pack()
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
schermata.mainloop()
python python-3.x tkinter chatterbot
add a comment |
I'm trying to create a chatbot program with CHATTERBOT MODULE and TKINTER.
It's almost ok, in fact my problem is that every button-click, the program creates me new labels, with command risposta.pack()
.
My intent is creating just one label and update it every other button-click.
How can I do it?
MY CODING:
from chatterbot import ChatBot
from tkinter import *
import time
from chatterbot.trainers import ListTrainer
bot = ChatBot(
"GUI Bot",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter='chatterbot.input.VariableInputTypeAdapter',
output_adapter='chatterbot.output.OutputAdapter',
database='../database,db',
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
with open('/home/griguols/Scrivania/chatterbot/istruzioni.txt') as istruzioni:
conversation = istruzioni.readlines()
bot.set_trainer(ListTrainer)
bot.train(conversation)
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta = Label(schermata, text=str(response.text))
risposta.pack()
schermata = Tk()
ment = StringVar()
schermata.geometry('1000x500')
schermata.title('OMERO')
titolo = Label(schermata,text='OMERO')
titolo.pack()
input = Entry(schermata,textvariable=ment)
input.pack()
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
schermata.mainloop()
python python-3.x tkinter chatterbot
I'm trying to create a chatbot program with CHATTERBOT MODULE and TKINTER.
It's almost ok, in fact my problem is that every button-click, the program creates me new labels, with command risposta.pack()
.
My intent is creating just one label and update it every other button-click.
How can I do it?
MY CODING:
from chatterbot import ChatBot
from tkinter import *
import time
from chatterbot.trainers import ListTrainer
bot = ChatBot(
"GUI Bot",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter='chatterbot.input.VariableInputTypeAdapter',
output_adapter='chatterbot.output.OutputAdapter',
database='../database,db',
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
with open('/home/griguols/Scrivania/chatterbot/istruzioni.txt') as istruzioni:
conversation = istruzioni.readlines()
bot.set_trainer(ListTrainer)
bot.train(conversation)
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta = Label(schermata, text=str(response.text))
risposta.pack()
schermata = Tk()
ment = StringVar()
schermata.geometry('1000x500')
schermata.title('OMERO')
titolo = Label(schermata,text='OMERO')
titolo.pack()
input = Entry(schermata,textvariable=ment)
input.pack()
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
schermata.mainloop()
python python-3.x tkinter chatterbot
python python-3.x tkinter chatterbot
asked Nov 25 '18 at 16:24
Marco GriguoliMarco Griguoli
102
102
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
To solve this issue, you can pack the label
(only one time) after the button
, so the last part of the code would look as follows:
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
risposta = Label(schermata, text="")
risposta.pack()
schermata.mainloop()
Then, change the command function so that it only updates the text of the already packed label:
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta['text']=str(response.text)
PS: I could not execute the with
scope since you have not provided the .txt file. For you next post, please consider providing an MCVE.
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
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%2f53469489%2fauto-update-label-with-the-pressing-of-a-tkinter-button%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
To solve this issue, you can pack the label
(only one time) after the button
, so the last part of the code would look as follows:
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
risposta = Label(schermata, text="")
risposta.pack()
schermata.mainloop()
Then, change the command function so that it only updates the text of the already packed label:
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta['text']=str(response.text)
PS: I could not execute the with
scope since you have not provided the .txt file. For you next post, please consider providing an MCVE.
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
add a comment |
To solve this issue, you can pack the label
(only one time) after the button
, so the last part of the code would look as follows:
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
risposta = Label(schermata, text="")
risposta.pack()
schermata.mainloop()
Then, change the command function so that it only updates the text of the already packed label:
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta['text']=str(response.text)
PS: I could not execute the with
scope since you have not provided the .txt file. For you next post, please consider providing an MCVE.
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
add a comment |
To solve this issue, you can pack the label
(only one time) after the button
, so the last part of the code would look as follows:
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
risposta = Label(schermata, text="")
risposta.pack()
schermata.mainloop()
Then, change the command function so that it only updates the text of the already packed label:
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta['text']=str(response.text)
PS: I could not execute the with
scope since you have not provided the .txt file. For you next post, please consider providing an MCVE.
To solve this issue, you can pack the label
(only one time) after the button
, so the last part of the code would look as follows:
bottone = Button(schermata,text='PARLA CON OMERO',command=command)
bottone.pack()
risposta = Label(schermata, text="")
risposta.pack()
schermata.mainloop()
Then, change the command function so that it only updates the text of the already packed label:
def command():
global risposta
user_input = input.get()
response = bot.get_response(user_input)
risposta['text']=str(response.text)
PS: I could not execute the with
scope since you have not provided the .txt file. For you next post, please consider providing an MCVE.
edited Nov 25 '18 at 17:01
answered Nov 25 '18 at 16:54
David DuranDavid Duran
534925
534925
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
add a comment |
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
Thanks too much David Duran, but what is exactly an MCVE?
– Marco Griguoli
Nov 25 '18 at 18:30
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
You are welcome. Please consider accepting the answer to close the question. As explained in the link, an MCVE is a Minimal, Complete, Verifiable Example.
– David Duran
Nov 25 '18 at 20:44
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%2f53469489%2fauto-update-label-with-the-pressing-of-a-tkinter-button%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