Cannot encode object: pymongoGet contents of a Tkinter Entry widgetHow to know if an object has an attribute in PythonDetermine the type of an object?null object in Python?ttk tkinter multiple frames/windowsHow to sort mongodb with pymongoUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)TkInter Frame doesn't load if another function is calledEntry widget row expansion in tkinterImporting Tkinter and rowspan/sticky questionCreating a variable from one class to another
Why is it easier to balance a non-moving bike standing up than sitting down?
Will generated tokens be progressively stronger when using Cathar's Crusade and Sorin, Grim Nemesis?
How does DC work with natural 20?
Prime sieve in Python
How can you guarantee that you won't change/quit job after just couple of months?
How to make clear to people I don't want to answer their "Where are you from?" question?
Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?
Are all Ringwraiths called Nazgûl in LotR?
UK - Working without a contract. I resign and guy wants to sue me
What are the pros and cons for the two possible "gear directions" when parking the car on a hill?
How do you pronounce the letter "t" before "h"?
Do I have to explain the mechanical superiority of the player-character within the fiction of the game?
How did Gollum enter Moria?
Story about a space war, and a human prisoner of war captured by alien enemy
Get list of shortcodes from content
How to maintain a closed environment for one person for a long period of time
What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?
Why tighten down in a criss-cross pattern?
Is there a term for the belief that "if it's legal, it's moral"?
Count All Possible Unique Combinations of Letters in a Word
How to parse 「場合でも」
What is the highest voltage from the power supply a Raspberry Pi 3 B can handle without getting damaged?
Why does independence imply zero correlation?
Should the party get XP for a monster they never attacked?
Cannot encode object: pymongo
Get contents of a Tkinter Entry widgetHow to know if an object has an attribute in PythonDetermine the type of an object?null object in Python?ttk tkinter multiple frames/windowsHow to sort mongodb with pymongoUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)TkInter Frame doesn't load if another function is calledEntry widget row expansion in tkinterImporting Tkinter and rowspan/sticky questionCreating a variable from one class to another
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm fairly new to programming and basically I have no idea what I'm doing.
I'm trying to make a write simple UI that that can take an input and write it to a mongodb.
import pymongo
from tkinter import *
from tkinter import ttk
class Input:
def __init__(self, root,):
self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")
self.mydb = self.myclient["mydatabase"]
self.mycol = self.mydb["input"]
title_label = Label(root, text="input")
title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
self.input_value = StringVar(root, value="")
self.input = ttk.Entry(root, textvariable=self.input_value)
self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)
def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)
root = Tk()
In = Input(root)
root.mainloop()
When trying to run this I get
bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>
I tried converting input_value to 'normal' string
self.input_value = str(StringVar(root, value=""))
By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.
What am I doing wrong?
python mongodb tkinter pymongo
add a comment |
I'm fairly new to programming and basically I have no idea what I'm doing.
I'm trying to make a write simple UI that that can take an input and write it to a mongodb.
import pymongo
from tkinter import *
from tkinter import ttk
class Input:
def __init__(self, root,):
self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")
self.mydb = self.myclient["mydatabase"]
self.mycol = self.mydb["input"]
title_label = Label(root, text="input")
title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
self.input_value = StringVar(root, value="")
self.input = ttk.Entry(root, textvariable=self.input_value)
self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)
def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)
root = Tk()
In = Input(root)
root.mainloop()
When trying to run this I get
bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>
I tried converting input_value to 'normal' string
self.input_value = str(StringVar(root, value=""))
By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.
What am I doing wrong?
python mongodb tkinter pymongo
Other way around. Rather than "assign a simple string" you need to coerceself.input_value
to a "simple string", or at least a valid type for the BSON serializer. So"input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
1
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00
add a comment |
I'm fairly new to programming and basically I have no idea what I'm doing.
I'm trying to make a write simple UI that that can take an input and write it to a mongodb.
import pymongo
from tkinter import *
from tkinter import ttk
class Input:
def __init__(self, root,):
self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")
self.mydb = self.myclient["mydatabase"]
self.mycol = self.mydb["input"]
title_label = Label(root, text="input")
title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
self.input_value = StringVar(root, value="")
self.input = ttk.Entry(root, textvariable=self.input_value)
self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)
def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)
root = Tk()
In = Input(root)
root.mainloop()
When trying to run this I get
bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>
I tried converting input_value to 'normal' string
self.input_value = str(StringVar(root, value=""))
By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.
What am I doing wrong?
python mongodb tkinter pymongo
I'm fairly new to programming and basically I have no idea what I'm doing.
I'm trying to make a write simple UI that that can take an input and write it to a mongodb.
import pymongo
from tkinter import *
from tkinter import ttk
class Input:
def __init__(self, root,):
self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")
self.mydb = self.myclient["mydatabase"]
self.mycol = self.mydb["input"]
title_label = Label(root, text="input")
title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
self.input_value = StringVar(root, value="")
self.input = ttk.Entry(root, textvariable=self.input_value)
self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)
def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)
root = Tk()
In = Input(root)
root.mainloop()
When trying to run this I get
bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>
I tried converting input_value to 'normal' string
self.input_value = str(StringVar(root, value=""))
By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.
What am I doing wrong?
python mongodb tkinter pymongo
python mongodb tkinter pymongo
edited Mar 25 at 14:21
Bryan Oakley
228k22302449
228k22302449
asked Mar 25 at 7:35
DracoTomesDracoTomes
112
112
Other way around. Rather than "assign a simple string" you need to coerceself.input_value
to a "simple string", or at least a valid type for the BSON serializer. So"input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
1
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00
add a comment |
Other way around. Rather than "assign a simple string" you need to coerceself.input_value
to a "simple string", or at least a valid type for the BSON serializer. So"input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
1
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00
Other way around. Rather than "assign a simple string" you need to coerce
self.input_value
to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Other way around. Rather than "assign a simple string" you need to coerce
self.input_value
to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
1
1
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00
add a comment |
1 Answer
1
active
oldest
votes
Thanks Neil Lunn.
entry = "input": self.input_value.get()
is now working using the get method.
Another problem I found is that I wrote
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
It actually needs to be
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)
Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.
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%2f55333093%2fcannot-encode-object-tkinter-stringvar-object-pymongo%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
Thanks Neil Lunn.
entry = "input": self.input_value.get()
is now working using the get method.
Another problem I found is that I wrote
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
It actually needs to be
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)
Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.
add a comment |
Thanks Neil Lunn.
entry = "input": self.input_value.get()
is now working using the get method.
Another problem I found is that I wrote
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
It actually needs to be
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)
Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.
add a comment |
Thanks Neil Lunn.
entry = "input": self.input_value.get()
is now working using the get method.
Another problem I found is that I wrote
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
It actually needs to be
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)
Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.
Thanks Neil Lunn.
entry = "input": self.input_value.get()
is now working using the get method.
Another problem I found is that I wrote
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
It actually needs to be
self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)
Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.
answered Mar 25 at 8:36
DracoTomesDracoTomes
112
112
add a comment |
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%2f55333093%2fcannot-encode-object-tkinter-stringvar-object-pymongo%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
Other way around. Rather than "assign a simple string" you need to coerce
self.input_value
to a "simple string", or at least a valid type for the BSON serializer. So"input": str(self.input_value)
– Neil Lunn
Mar 25 at 7:45
Doing that still results in "PY_VAR0" being written to the database.
– DracoTomes
Mar 25 at 7:52
1
Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.
– Neil Lunn
Mar 25 at 8:00