Home > application development > Glade, quickly and changing an image with code

Glade, quickly and changing an image with code

August 5Hits:1
Advertisement

I have created the default ubuntu-application template using quickly and I'm trying to work out how to change the displayed image through code.

The default image shows an ubuntu logo with the path ".../media/background.png" within glade.

If I open the projects window python file (testWindow.py as the projects name is test) and add the following lines at the base of the finish_initializing function (changing nothing else within the default files created),

self.PNG = self.builder.get_object("image1") self.PNG.set_from_file("../media/background.png") 

The program runs but instead of the ubuntu logo, the small missing file icon displays. However no error message displays in the terminal and changing the png file to another png, or moving it to the same directory as the python file (changing the second lines file to "background.png") gives the same issue. I can use the clear() function to remove the image successfully but I'm clearly doing something wrong and I can't seem to make any headway into the documentation for the image widget.

In case it helps to know what I'm aiming to do, I'm trying to create a simple flashcard program, displaying a Japanese character and requiring the user to input the correct pronunciation and displaying another image of a new character if the user is successful.

Thank you for any help you can give!

Answers

The path you're giving set_from_file is relative to the glade file but not the python file. It's better to use full paths anyways as using relative paths often ends up having issues when you run the installed application. Quickly provides a nice helper function to give you the full path for a file found in the data/ folder. Try:

from test_lib.testconfig import get_data_file

[....]   

    self.image = self.builder.get_object("image1")
    self.background = get_data_file("media/background.png")
    self.image.set_from_file(self.background)

Related Articles

  • Glade, quickly and changing an image with codeAugust 5

    I have created the default ubuntu-application template using quickly and I'm trying to work out how to change the displayed image through code. The default image shows an ubuntu logo with the path ".../media/background.png" within glade. If I op

  • Working with quickly, are there any gtk.Builder code sketching tools that integrate?April 9

    Example: quickly create ubuntu-application testing quickly design #makes changes #insert some other command here that would be roughly equivalent to 'quickly sketch' quickly edit #to populate the sketched functions Willing to accept other gtk.Builder

  • How to quickly understand a huge piece of code

    How to quickly understand a huge piece of code September 22

    What tools and techniques do you use for exploring and learning an unknown code base? I am thinking of tools like grep, ctags, unit-tests, functional test, class-diagram generators, call graphs, code metrics like sloccount, and so on. I'd be interest

  • Can't center dialog window above main window when using Glade (Quickly)September 11

    I have a dialog opening when I press a button in my application and I want it to center above the application's main window, but I can't find a way to do this. I'm using Quickly (Python) and Glade. In Glade I've tried the following settings: Window T

  • Dynamicly add or remove items from list and tree in pygtk and quickly (glade)September 4

    I'm trying to make some mini CRM application in python using gtk(pygtk), glade and started to develop it using quickly(which is awesome). I'm created some dialogs and added listview to the GUI using glade) but when I try to add some items to the list

  • Garbled Code added to Email Field at 'Quick Edit' comment screenMarch 1

    when I edit a comment normally the email just contains the email like it should, but when I use 'quick edit comment' then there's code added in the email field after the email. This code to be specific: /* <![CDATA[ */!function(){try{var t="curren

  • Are #regions an antipattern or code smell?February 28

    C# allows the use of #region/#endregion keywords to make areas of code collapsible in the editor. Whenever I do this though I do it to hide large chunks of code that could probably be refactored into other classes or methods. For example I have seen

  • How do I call a function in Quickly?July 2

    How to call function in quickly? Here is my code: def finish_initializing(self, builder): # pylint: disable=E1002 super(projectWindow, self).finish_initializing(builder) self.AboutDialog = AboutprojectDialog self.PreferencesDialog = Preferencesprojec

  • How important are code formatting guidelines? September 11

    Coding standards are common in any software development organization, but how important are they to follow? I can understand the need for some consistency, but when dealing with simple things like the position of braces, line length, etc., I'm not su

  • How to write less code October 4

    A quality what I would like to develop is to write more concise code. With writing more concise, at least in my opinion, the opportunity to add bugs to the code is smaller. It is easier to read the code for other. My question is if it is something th

  • How many lines of code can a C# developer produce per month? January 26

    An executive at my workplace asked me and my group of developers the question: How many lines of code can a C# developer produce per month? An old system was to be ported to C# and he would like this measure as part of the project planning. From some

  • How to handle a 'bad code' interview? March 29

    A 'bad code' interview is one where the interviewee is shown a snippet of 'bad code' and asked to correct it or point out things that are wrong with it. I have trouble with these interviews because it takes me some time to read the code, figure out w

  • What is a good way to refactor a large, terribly written code base by myself? April 8

    This question already has an answer here: What is the most effective way to add functionality to unfamiliar, structurally unsound code? [duplicate] 8 answers I've inherited 200K lines of spaghetti code - what now? 19 answers So I'm sitting down to a

  • How do you track common, but rarely used code?

    How do you track common, but rarely used code?May 5

    General OO teaches us to encapsulate and best practices teach us organization. So we end up with re-useable self-documenting code that relieves us of any details regarding implementation. So, if I need to invoke the windows command line I use my comm

  • Best Practices for Handing over Legacy CodeNovember 7

    In a couple of months a colleague will be moving on to a new project and I will be inheriting one of his projects. To prepare, I have already ordered Michael Feathers' Working Effectively with Legacy Code. But this books as well as most questions on

  • Detailed quickly tutorialApril 2

    Hi I kindly need a more detailed quickly tutorial that explain the python code./ For example, adding a login form to an application --------------Solutions------------- Since you don't tell us what you already found, I will just give a list of hopefu

  • F# mergesort code : where to improveJune 16

    I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? open System open System.Windows open System.Collections.Generic let shuffle (l:'a array) = let ileft = LinkedList<int>(seq { 0 .. (l.Length

  • Why does my Quickly app install in /usr/bin instead of /opt? July 6

    As I've finished my app for the App Showdown, I ran quickly submitubuntu, but I found that my app is installed inside /usr/bin. What? I need it at /opt! How can I fix this? --------------Solutions------------- Right, after running quickly package --v

  • How to force Quickly to NOT include a dependency? (Specifically: apport)August 15

    My case is this - the quickly-generated application contains some apport code, so quickly inserts python-apport in the dependencies list. I would like the application to be installable and run on Linux Mint as well, where this package is missing. I w

  • How to create a sliding widget (GTK+, Quickly)

    How to create a sliding widget (GTK+, Quickly)September 5

    Recently I've seen this widget in Gedit: It appears when you press Ctrl + F. What I am interested is in how to get the sliding effect. Any suggestion will be appreciated. --------------Solutions------------- I have achieved a fade-out effect using pu

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.524 s.