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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:46:53+00:00 2026-06-15T01:46:53+00:00

(I edited the whole question to be more clear) Hello, I have never had

  • 0

(I edited the whole question to be more clear)


Hello,

I have never had any affairs with Python GUI libraries. I know there are plenty and well documented, but as I need only one single snippet, I would dislike to dive deep into documentations to seek for a way how to do it. If I am going to write a GUI program, I surely would do that, but this is needed only as a few lines for my ad hoc script.

What would be the easiest and the most straightforward way for me (GUI noob) to write in Python following piece of code? Less lines = more happiness.

  1. Grab a JPEG picture by filename.
  2. Display it’s thumbnail.
  3. Below the thumbnail display a textfield so the user can type in a caption.
  4. Wait until user hits ENTER key on his/her keyboard. In that case, close and return the input.
  5. …or wait until user hits DELETE key. In that case, close and return an information about the decision (to delete the picture).

Dependencies or Linux-only solutions are okay. I need to run this on Xubuntu machine. Any code snippets, please? I believe this is a matter of 5 minutes for someone skilled in Python GUI field. I would need to study loads of library docs. Thank you!

  • 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-15T01:46:54+00:00Added an answer on June 15, 2026 at 1:46 am

    Below is a minimal python script that more or less fits the spec.

    It requires python2 and pyqt4 packages to be installed, and it won’t work with python3 (although it could quite easily be adapted to do so if necessary).

    If the user types in a valid caption and presses enter, the script will return with status code 0 and print the caption to stdout; otherwise, if the user enters an invalid caption (empty or whitespace only), or simply closes the dialog without doing anything, the script will return with status code 1 and print nothing.

    example bash usage:

    $ CAPTION=$(python imgviewer.py image.jpg)
    $ [ $? -eq 0 ] && echo $CAPTION 
    

    imgviewer.py:

    import sys, os
    from PyQt4 import QtGui, QtCore
    
    class Dialog(QtGui.QDialog):
        def __init__(self, path):
            QtGui.QDialog.__init__(self)
            self.viewer = QtGui.QLabel(self)
            self.viewer.setMinimumSize(QtCore.QSize(400, 400))
            self.viewer.setScaledContents(True)
            self.viewer.setPixmap(QtGui.QPixmap(path))
            self.editor = QtGui.QLineEdit(self)
            self.editor.returnPressed.connect(self.handleReturnPressed)
            layout = QtGui.QVBoxLayout(self)
            layout.addWidget(self.viewer)
            layout.addWidget(self.editor)
    
        def handleReturnPressed(self):
            if self.editor.text().simplified().isEmpty():
                self.reject()
            else:
                self.accept()
    
    if __name__ == '__main__':
    
        app = QtGui.QApplication(sys.argv)
        args = app.arguments()[1:]
        if len(args) == 1:
            dialog = Dialog(args[0])
            if dialog.exec_() == QtGui.QDialog.Accepted:
                print dialog.editor.text().simplified().toLocal8Bit().data()
                sys.exit(0)
        else:
            print 'ERROR: wrong number of arguments'
        sys.exit(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
** This question has been edited to make it simpler and more focused **
In response to the helpful comments, I have edited the original question (where I
I edited my whole question, so do not wonder :) Well, I want to
The whole story; I have some KeyValuePairs that I need to store in a
I have a form that can be filled, saved, loaded and re-edited. When it
I have a simple question. I have a few files, one file is around
edit as question is unanswered I have a filtered output based on 1 criteria
This is pretty easy question, but I have been unable to find the solution
Before starting, I do have a very particular question and if you want to

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.