Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:47:40+00:00 2026-06-18T04:47:40+00:00

I’m trying to make my way through the documenation, but I’m having a hard

  • 0

I’m trying to make my way through the documenation, but I’m having a hard time trying to find three specific things.

  1. What is a text input.
  2. How to get the text in a text input.
  3. How to set the text on a text input.

Basically I would like to do as I just did in this example for javascript (it’s really simple):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SmallForm</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>var db = openDatabase('mydb', '1.0', 'temporal database', 2 * 1024 * 1024);
    db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE foo (id unique, field1 text, field2 text)');
    });
    saveData = function(){
        db.transaction(function (tx) {
            var id = $('input[name=id]').val();
            var field1 = $('input[name=field1]').val();
            var field2 = $('input[name=field2]').val();
            tx.executeSql('insert or replace into foo values (?, ?, ?)', [id , field1, field2]);
        });
    };
    loadData = function(){
        db.transaction(function (tx) {
            var id = $('input[name=id]').val();
            tx.executeSql('select * from foo where id =?', [id],function (tx, results) {
                var len = results.rows.length;
                if (len != 1){
                    var text = len > 1? "bad data" : "no data";
                    $('input[name=field1]').val(text);
                    $('input[name=field2]').val(text);
                }
                else {
                    $('input[name=field1]').val(results.rows.item(0).field1);
                    $('input[name=field2]').val(results.rows.item(0).field2);
                }
            });
        });
    };
    </script>
</head>
<body>
    <div class="line">ID:<input type="text" name="id" value="Introduce the ID first"><input type="button" onclick="loadData()" value="Load"></div>
    <div class="line">Field1:<input type="text" name="field1" value="some field"></div>
    <div class="line">Field2:<input type="text" name="field2" value="another field"></div>
    <div class="line"><input type="button" onclick="saveData()" value="Save"></div>
</body>
</html>

I could not find this documentation for Python and I don’t understand how the Tcl/Tk documentation maps to Python code. I guess I should check these:

  • http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm
  • http://www.tcl.tk/man/tcl8.4/TkCmd/contents.htm

But I understand nothing, either that is complex, I’m stupid or I skipped some important bits of information. Most probably it’s a combination of all the former.

Thank you. Sorry if I did something wrong. All replies and feedback are welcome.

PD: I’ve been working on the code from @mmgp and I’ve produced this:

import sqlite3, tkinter as tk

def save_data():
  insertQuery = 'insert or replace into allData values(%s)'%(','.join(map(lambda x:'?',fields)))
  cursor.execute(insertQuery, tuple(map(lambda x: variables[x].get(), fields)))
  db.commit()

def load_data():
  cursor.execute('select * from allData where %s = ?'%fields[0], [variables[fields[0]].get()])
  row = cursor.fetchone()
  if row is None:
    for f in fields:
      variables[f].set("Bad data request")
    return
  for i in range(len(fields)):
    variables[fields[i]].set(row[i])


root = tk.Tk()
root.title('Fielder2013')
fields = ['id', 'field1', 'field2']
variables = {}
buttons = {'Load':load_data, 'Save':save_data}
dfields = {}

for i in range(len(fields)):
  e = fields[i]
  dfields[e] = (tk.Label(text=e), tk.Entry())
  dfields[e][0].grid(row=i, column=0)
  dfields[e][1].grid(row=i, column=1)
  variables[e] = tk.StringVar()
  dfields[e][1]["textvariable"] = variables[e]
i = 0
for e in buttons:
  c = buttons[e]
  buttons[e] = tk.Button(text=e)
  buttons[e]['command'] = c
  buttons[e].grid(row = i, column=2)
  i+=1

with sqlite3.connect('database.sqlite3') as db:
  cursor = db.cursor()
  cursor.execute('create table if not exists allData (%s text unique%s)'%(
                 fields[0], ''.join(map(lambda e: ', %s text'%e, fields[1:]))))
  root.mainloop()
  db.commit()

The code may not be the clearest code you have ever seen but my little brain was trying to grasp some new concepts. I think it may be helpful for someone though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:47:41+00:00Added an answer on June 18, 2026 at 4:47 am

    The official documentation can always be found at http://docs.python.org/2/library/tkinter.html. Also, searching for terms like “python tkinter” will return a lot of other places with useful documentation.

    Following is an example that does nearly nothing, but replicates your code without calling into some database.

    import Tkinter
    
    def save_data(form):
        for widget in form:
            print widget.get()
    
    def load_data(id_value, form):
        for i, widget in enumerate(form):
            widget.delete(0, 'end')
            widget.insert(0, id_value * (i + 2))
    
    root = Tkinter.Tk()
    
    lbl_id = Tkinter.Label(text=u'ID')
    entry_id = Tkinter.Entry()
    entry_load = Tkinter.Button(text=u'Load')
    lbl_field1 = Tkinter.Label(text=u'Field 1')
    entry_field1 = Tkinter.Entry()
    entry_save = Tkinter.Button(text=u'Save')
    
    lbl_id.grid(row=0, column=0)
    entry_id.grid(row=0, column=1)
    entry_load.grid(row=0, column=2)
    lbl_field1.grid(row=1, column=0)
    entry_field1.grid(row=1, column=1)
    entry_save.grid(row=2, column=2)
    
    form = [entry_field1]
    entry_load['command'] = lambda: load_data(entry_id.get(), form)
    entry_save['command'] = lambda: save_data(form)
    
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.