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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:30:27+00:00 2026-06-12T01:30:27+00:00

I use Python 2.7 and wx on Ubuntu 12.04. I wrote a tiny, tiny

  • 0

I use Python 2.7 and wx on Ubuntu 12.04.

I wrote a tiny, tiny image viewer in Python using wx. Everything works just great but I have problems with size of my app’s main window.

When I open an ordinary-size picture, I see:

enter image description here

which is just fine.

But when I open another file, lets say sth like this (an image of a biiiiig graph):

enter image description here

my app window has a wrong width, I mean take a look at menu its .. too tight and you dont even see an “Edit” option properly.

How to fix it? I just started with wx in Python, so please, be patient 🙂

My code:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import wx
import os

class MyGUIApp(wx.App):

    def __init__(self, redirect=False, filename=None):

        wx.App.__init__(self, redirect, filename)
        self.frame = wx.Frame(None, title='MyGUIApp v0.2')
        self.panel = wx.Panel(self.frame)

        self.filename = ''
        self.dirname = ''
        width, height = wx.DisplaySize()
        self.pictureMaxSize = 500

        img = wx.EmptyImage(self.pictureMaxSize, self.pictureMaxSize)
        self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))

        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainSizer.Add(self.imageCtrl, 0, wx.ALL|wx.CENTER, 5)
        self.panel.SetSizer(self.mainSizer)
        self.mainSizer.Fit(self.frame)

        self.createMenus()  
        self.connectItemsWithEvents()
        self.createKeyboardShortcuts()

        self.frame.SetMenuBar(self.menuBar)
        self.frame.Show()

    def connectItemsWithEvents(self) :
        self.Bind(wx.EVT_MENU, self.openEvent, self.openItem)
        self.Bind(wx.EVT_MENU, self.clearEvent, self.clearItem)

    def createKeyboardShortcuts(self) :
      self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('C'), self.clearItem.GetId()),
                                            (wx.ACCEL_CTRL, ord('O'), self.openItem.GetId()),
                                            ])
      self.frame.SetAcceleratorTable(self.accel_tbl)

    def createMenus(self) :
        self.menuBar = wx.MenuBar()
        self.menuFile = wx.Menu()

        self.menuBar.Append(self.menuFile, '&File')      
        self.openItem = wx.MenuItem(self.menuFile, wx.NewId(), u'&open ...\tCTRL+O')
        #self.openItem.SetBitmap(wx.Bitmap('images/document-open.png'))
        self.menuFile.AppendItem(self.openItem)

        self.menuEdit = wx.Menu()
        self.menuBar.Append(self.menuEdit, '&Edit')
        self.clearItem = wx.MenuItem(self.menuEdit, wx.NewId(), '&Clear\tCTRL+C')
        #self.clearItem.SetBitmap(wx.Bitmap('images/clear.png'))
        self.menuEdit.AppendItem(self.clearItem)


    def openEvent(self, event) :
        openDialog = wx.FileDialog(self.frame, u'Open file', "File", "", "*.*", wx.OPEN)
        if openDialog.ShowModal() == wx.ID_OK :
            self.filename = openDialog.GetFilename()
            self.dirname = openDialog.GetDirectory()
            self.draw(os.path.join(self.dirname, self.filename))
        openDialog.Destroy()

    def clearEvent(self, event) :
        img = wx.EmptyImage(self.pictureMaxSize, self.pictureMaxSize)
        self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.frame.SetSize((self.pictureMaxSize, self.pictureMaxSize))
        self.filename = ''
        self.dirname = ''

    def draw(self, filename) :
        image_name = filename
        img = wx.Image(filename, wx.BITMAP_TYPE_ANY)
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.pictureMaxSize
            NewH = self.pictureMaxSize * H / W
        else:
            NewH = self.pictureMaxSize
            NewW = self.pictureMaxSize * W / H
        img = img.Scale(NewW,NewH)
        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.panel.Refresh()
        self.mainSizer.Fit(self.frame)

if __name__ == '__main__':
    app = MyGUIApp()
    app.MainLoop()
  • 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-12T01:30:28+00:00Added an answer on June 12, 2026 at 1:30 am

    You can call self.Frame.SetMinSize(w, h) to force the window to have a reasonable minimum height and width, but you will want to add scrollbars so that you can see all of the image… I tried to do that but I am a beginner as well and don’t have the time at the moment, sorry. Good Luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use python based as well as rails applications on ubuntu linux. We have
I want to use a python script on my Ubuntu 10.04 64 bit but
I use python 2.7. I have data in file 'a': myname1@abc.com;description1 myname2@abc.org;description2 myname3@this_is_ok.ok;description3 myname5@qwe.in;description4
I use Python in one of my products. I compiled the source code using:
I am using GNU/Linux (Ubuntu + Gnome). I have been using netbeans on windows
Using Python 2.6, I wrote a script in Windows XP. The script does the
I use python bindings for FontForge under Ubuntu. It constantly runs into crash without
I am trying to use the google appengine python SKD from my ubuntu lucid.
I would like to be able to use a Python script that I wrote
I would like to retrieve multiple log files from an Ubuntu server (using Python

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.