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

  • SEARCH
  • Home
  • 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 8279381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:19:11+00:00 2026-06-08T09:19:11+00:00

Partly to learn, partly to help myself I’m trying to write an app with

  • 0

Partly to learn, partly to help myself I’m trying to write an app with a GUI for encoding/decoding. At the moment, I’m just working on encoding.

I’ve a Tkinter menu which feeds a variable to the GUI def with item specified as base64, urllib or encoding hex.

A button exists on the GUI which runs gettext. I’m having difficulty getting encodedvar to contain the process + variable and for the results to be displayed in the bottom frame.

On running this, at the moment, the following appears (as an example) in the bottom frame – blackcat obviously being what was entered into the middle frame.

base64.encodestring('blackcat
')

Have 2 issues:

  1. Getting the code to actually be formatted correctly i.e. not over 2 lines as shown above

  2. Have the code run, rather than the command itself be printed in the bottom.

The code I’m using is displayed below:

def gui(item):
    if item == 'encode_b64':
        process = 'base64.encodestring'
    elif item == 'encode_url':
        process = 'urllib.quote_plus'
    else:
        process = '.encode("hex")'


    def getText():
        bottomtext.delete(1.0, END)
        var = middletext.get(1.0, END)

        encodedvar = process + "('%s')" % var
        bottomtext.insert(INSERT, encodedvar)
  • 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-08T09:19:13+00:00Added an answer on June 8, 2026 at 9:19 am

    The text widget guarantees a trailing newline, so you should use "end-1c" when getting the contents of the text widget. Doing that guarantees you get only the text that was entered by the user without that extra trailing newline.

    Second, to run the function instead of printing it out, you can store the actual function in a variable, then use the variable to invoke the function:

    if item == 'encode_b64':
        process = base64.encodestring
    elif item == 'encode_url':
        process = urllib.quote_plus
    else:
        process = default_encode
    
    def default_encode(s):
        s.encode("hex")
    ...
    bottomtext.insert(INSERT, process(var))
    

    The above can be written a bit more succinctly like this:

    mapping = {"encode_b64": base64.encodestring,
               "encode_url": urllib.quote_plus}
    process = mapping.get(item, default_encode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to animate an image which is partly hidden (via overflow: hidden) inside
Ok, so basically I have this part of the .htaccess partly working, but not
I'm trying to implement a quite simple UI using SpringLayout (partly because I, as
This is partly a jquery question, but most javascript. I just don't know javascript
I tried the following and it was partly working: >> s.methods.map {|n| n if
I've just made an upgrade and now partly thinking on web-server directory structure for
Hello, I am trying to learn Twilio API. When I [send SMS through php][1]
This is a noob question. I'm trying to learn how to use SWIG to
I'm trying to learn how to do passphrase-based encryption with Java. I'm finding several
I compile my own PHP, partly to learn more about how PHP is put

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.