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 7530527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:56:07+00:00 2026-05-30T04:56:07+00:00

I’ve no idea why I haven’t been able to find a good solution to

  • 0

I’ve no idea why I haven’t been able to find a good solution to this problem yet, it seems very elementary to me .. though not elementary enough to figure it out satisfactorily.
A chapter project in a cryptology book Im reading instructs to write a simple mono-alphabetic cipher in your preferred language … I chose Python.

It starts with a simple tkinter app. with some widgets, lol … duh. Anyways here’s the relevant code:

from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror


class Application(Frame):
    def __init__(self, master):
        """ Initialize Frame. """
        super(Application, self).__init__(master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        """ Set all program widgets. """
        # set all labels
        Label(self, text = "Plaintext File: ")\
            .grid(row=0, column=0, sticky=W)
        Label(self, text = "Ciphertext: ")\
            .grid(row=3, column=0, sticky=W)
        Label(self, text = "Offset: ")\
            .grid(row=2, column=0, sticky=W)

    # set buttons
    Button(self, text = "Browse", command=self.load_file, width=10)\
        .grid(row=1, column=0, sticky=W)

    # set entry field
    self.file_name = Text(self, width=39, height=1, wrap=WORD)
    self.file_name.grid(row=1, column=1, columnspan=4, sticky=W)

    # set display field
    self.output_display = Text(self, width=50, height=5, wrap=WORD)
    self.output_display.grid(row=4, column=0, columnspan=4, sticky=W)

    # set offset amount spinbox
    self.offset_amt = IntVar()

    self.offset_amt = Spinbox(self, from_=1, to=13)
    self.offset_amt.grid(row=2, column=1, sticky=W)

    # set shift direction
    self.shift_dir = StringVar()
    self.shift_dir.set('r')

    Radiobutton(self, text="Shift Right", variable=self.shift_dir, value='r')\
        .grid(row=2, column=2, sticky=W)
    Radiobutton(self, text="Shift Left", variable=self.shift_dir, value='l')\
        .grid(row=2, column=3, sticky=W)


def load_file(self):

    self.filename = askopenfilename(initialdir='~')


    if self.filename: 
        try: 
            #self.settings.set(self.filename)
            self.file_name.delete(0.0, END)
            self.file_name.insert(0.0, open(self.filename, 'r'))
        except IOError: 
            showerror("Open Source File", "Failed to read file \n'%s'"%self.filename)
            return


def main():
    root = Tk()
    root.title("simple mono-alpha encrypter")
    root.geometry('450x250')
    app = Application(root)

for child in app.winfo_children(): 
    child.grid_configure(padx=3, pady=3)

root.mainloop()

main()

There’s only a very little of it that actually does anything besides create widgets right now, I decided to post it all since its not that involved yet and someone can get a good idea of where Im at.

My problem that I haven’t solved is that when I press use the ‘Browse’ button to choose a file to encrypt and then choose the file, the file content is displayed in the ‘file_name’ text widget, rather than the file name itself.

Im thinking that I have to change the ‘filename’ variable to not the actual file name but the file instead and then load the content of the File Name field from the open file dialog box in a ‘filename’ variable. I just haven’t been able to figure out how to do that yet.
Nor have I come across an appropriate method to do it.
Any guidance??

Thanks
F

  • 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-05-30T04:56:08+00:00Added an answer on May 30, 2026 at 4:56 am

    Displaying the Filename

    self.file_name.insert(0.0, self.filename)
    

    Displaying the File Contents

    You just need to read the data in from the file. See http://docs.python.org/library/stdtypes.html#file-objects

    with open(self.filename, 'r') as inp_file:
        self.file_name.insert(0.0, inp_file.read())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.