Perl/Gtk3, add a background image to a window The Next CEO of Stack OverflowVertically align text next to an image?When to use IMG vs. CSS background-image?How do I give text or an image a transparent background using CSS?Stretch and scale a CSS image in the background - with CSS onlyHow to make a div 100% height of the browser window?How to fix a locale setting warning from Perl?How do I combine a background-image and CSS3 gradient on the same element?How do I auto-resize an image to fit a 'div' container?How to vertically align an image inside a div?Using a SVG as background in Gtk3 with CSS

AB diagonalizable then BA also diagonalizable

Is there an equivalent of cd - for cp or mv

What does "shotgun unity" refer to here in this sentence?

Can someone explain this formula for calculating Manhattan distance?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Help! I cannot understand this game’s notations!

Is there such a thing as a proper verb, like a proper noun?

What was Carter Burke's job for "the company" in Aliens?

Can this note be analyzed as a non-chord tone?

When "be it" is at the beginning of a sentence, what kind of structure do you call it?

What CSS properties can the br tag have?

Strange use of "whether ... than ..." in official text

Won the lottery - how do I keep the money?

What difference does it make using sed with/without whitespaces?

Easy to read palindrome checker

From jafe to El-Guest

Is a distribution that is normal, but highly skewed, considered Gaussian?

Which one is the true statement?

Can I board the first leg of the flight without having final country's visa?

Is there a reasonable and studied concept of reduction between regular languages?

TikZ: How to fill area with a special pattern?

Does destroying a Lich's phylactery destroy the soul within it?

Can I use the word “Senior” as part of a job title directly in German?

How to explain the utility of binomial logistic regression when the predictors are purely categorical



Perl/Gtk3, add a background image to a window



The Next CEO of Stack OverflowVertically align text next to an image?When to use IMG vs. CSS background-image?How do I give text or an image a transparent background using CSS?Stretch and scale a CSS image in the background - with CSS onlyHow to make a div 100% height of the browser window?How to fix a locale setting warning from Perl?How do I combine a background-image and CSS3 gradient on the same element?How do I auto-resize an image to fit a 'div' container?How to vertically align an image inside a div?Using a SVG as background in Gtk3 with CSS










1















I'm trying to add a background image to a window. Using CSS styles, it's simple enough, but I only want to add the image to a single window, not all of them.



The script below creates two Gtk windows, one with CSS, the other without. It doesn't work because the CSS style is added to both windows.



I would be happy to add a background image to a Gtk3::Frame, or a Gtk3::Box, or even to avoid CSS altogether, but I can't get any of these methods to work.



I think the code is almost right, because it does work for adding a background image to just one Gtk3::TextView (but not both of them).



#!/usr/bin/perl
package bgtest;

use strict;
use diagnostics;
use warnings;

use Gtk3 '-init';
use Glib qw(TRUE FALSE);
use Cairo;

&drawWin(FALSE);
&drawWin(TRUE);

Gtk3->main();

sub drawWin

my ($cssFlag) = @_;

my $window = Gtk3::Window->new('toplevel');
$window->set_position('center');
$window->set_default_size(400, 300);
$window->signal_connect('delete-event' => sub

Gtk3->main_quit();
exit;
);

if ($cssFlag)

# Set up the window's background image using a CSS style
$window->set_title('CSS ON');

my $imagePath = "/home/YOURNAME/bg.png";

my $provider = Gtk3::CssProvider->new();
my $display = Gtk3::Gdk::Display::get_default();
my $screen = Gtk3::Gdk::Display::get_default_screen($display);
Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);

my $theming = "#my_win_id, window.background n";
$theming .= " background-image: url("$imagePath");n";
$theming .= " background-repeat: repeat;n";
$theming .= " background-position: top left;n";
$theming .= "";

$provider->load_from_data ([map ord, split //, $theming]);

my $context = $window->get_style_context();
$context->add_provider($provider, 600);

else

# Don't use a background image
$window->set_title('CSS OFF');


$window->show_all();

return $window;










share|improve this question


























    1















    I'm trying to add a background image to a window. Using CSS styles, it's simple enough, but I only want to add the image to a single window, not all of them.



    The script below creates two Gtk windows, one with CSS, the other without. It doesn't work because the CSS style is added to both windows.



    I would be happy to add a background image to a Gtk3::Frame, or a Gtk3::Box, or even to avoid CSS altogether, but I can't get any of these methods to work.



    I think the code is almost right, because it does work for adding a background image to just one Gtk3::TextView (but not both of them).



    #!/usr/bin/perl
    package bgtest;

    use strict;
    use diagnostics;
    use warnings;

    use Gtk3 '-init';
    use Glib qw(TRUE FALSE);
    use Cairo;

    &drawWin(FALSE);
    &drawWin(TRUE);

    Gtk3->main();

    sub drawWin

    my ($cssFlag) = @_;

    my $window = Gtk3::Window->new('toplevel');
    $window->set_position('center');
    $window->set_default_size(400, 300);
    $window->signal_connect('delete-event' => sub

    Gtk3->main_quit();
    exit;
    );

    if ($cssFlag)

    # Set up the window's background image using a CSS style
    $window->set_title('CSS ON');

    my $imagePath = "/home/YOURNAME/bg.png";

    my $provider = Gtk3::CssProvider->new();
    my $display = Gtk3::Gdk::Display::get_default();
    my $screen = Gtk3::Gdk::Display::get_default_screen($display);
    Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);

    my $theming = "#my_win_id, window.background n";
    $theming .= " background-image: url("$imagePath");n";
    $theming .= " background-repeat: repeat;n";
    $theming .= " background-position: top left;n";
    $theming .= "";

    $provider->load_from_data ([map ord, split //, $theming]);

    my $context = $window->get_style_context();
    $context->add_provider($provider, 600);

    else

    # Don't use a background image
    $window->set_title('CSS OFF');


    $window->show_all();

    return $window;










    share|improve this question
























      1












      1








      1


      2






      I'm trying to add a background image to a window. Using CSS styles, it's simple enough, but I only want to add the image to a single window, not all of them.



      The script below creates two Gtk windows, one with CSS, the other without. It doesn't work because the CSS style is added to both windows.



      I would be happy to add a background image to a Gtk3::Frame, or a Gtk3::Box, or even to avoid CSS altogether, but I can't get any of these methods to work.



      I think the code is almost right, because it does work for adding a background image to just one Gtk3::TextView (but not both of them).



      #!/usr/bin/perl
      package bgtest;

      use strict;
      use diagnostics;
      use warnings;

      use Gtk3 '-init';
      use Glib qw(TRUE FALSE);
      use Cairo;

      &drawWin(FALSE);
      &drawWin(TRUE);

      Gtk3->main();

      sub drawWin

      my ($cssFlag) = @_;

      my $window = Gtk3::Window->new('toplevel');
      $window->set_position('center');
      $window->set_default_size(400, 300);
      $window->signal_connect('delete-event' => sub

      Gtk3->main_quit();
      exit;
      );

      if ($cssFlag)

      # Set up the window's background image using a CSS style
      $window->set_title('CSS ON');

      my $imagePath = "/home/YOURNAME/bg.png";

      my $provider = Gtk3::CssProvider->new();
      my $display = Gtk3::Gdk::Display::get_default();
      my $screen = Gtk3::Gdk::Display::get_default_screen($display);
      Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);

      my $theming = "#my_win_id, window.background n";
      $theming .= " background-image: url("$imagePath");n";
      $theming .= " background-repeat: repeat;n";
      $theming .= " background-position: top left;n";
      $theming .= "";

      $provider->load_from_data ([map ord, split //, $theming]);

      my $context = $window->get_style_context();
      $context->add_provider($provider, 600);

      else

      # Don't use a background image
      $window->set_title('CSS OFF');


      $window->show_all();

      return $window;










      share|improve this question














      I'm trying to add a background image to a window. Using CSS styles, it's simple enough, but I only want to add the image to a single window, not all of them.



      The script below creates two Gtk windows, one with CSS, the other without. It doesn't work because the CSS style is added to both windows.



      I would be happy to add a background image to a Gtk3::Frame, or a Gtk3::Box, or even to avoid CSS altogether, but I can't get any of these methods to work.



      I think the code is almost right, because it does work for adding a background image to just one Gtk3::TextView (but not both of them).



      #!/usr/bin/perl
      package bgtest;

      use strict;
      use diagnostics;
      use warnings;

      use Gtk3 '-init';
      use Glib qw(TRUE FALSE);
      use Cairo;

      &drawWin(FALSE);
      &drawWin(TRUE);

      Gtk3->main();

      sub drawWin

      my ($cssFlag) = @_;

      my $window = Gtk3::Window->new('toplevel');
      $window->set_position('center');
      $window->set_default_size(400, 300);
      $window->signal_connect('delete-event' => sub

      Gtk3->main_quit();
      exit;
      );

      if ($cssFlag)

      # Set up the window's background image using a CSS style
      $window->set_title('CSS ON');

      my $imagePath = "/home/YOURNAME/bg.png";

      my $provider = Gtk3::CssProvider->new();
      my $display = Gtk3::Gdk::Display::get_default();
      my $screen = Gtk3::Gdk::Display::get_default_screen($display);
      Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);

      my $theming = "#my_win_id, window.background n";
      $theming .= " background-image: url("$imagePath");n";
      $theming .= " background-repeat: repeat;n";
      $theming .= " background-position: top left;n";
      $theming .= "";

      $provider->load_from_data ([map ord, split //, $theming]);

      my $context = $window->get_style_context();
      $context->add_provider($provider, 600);

      else

      # Don't use a background image
      $window->set_title('CSS OFF');


      $window->show_all();

      return $window;







      css perl gtk3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 18:01









      lesrollesrol

      756




      756






















          1 Answer
          1






          active

          oldest

          votes


















          0















          I'm trying to add a background image to a window. Using CSS styles,
          it's simple enough, but I only want to add the image to a single
          window, not all of them.




          Just remove the screen provider (and keep the window provider). So comment out the line:



          Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);





          share|improve this answer


















          • 1





            Thanks Håkon, you're the best!

            – lesrol
            Mar 8 at 7:48











          • @lesrol accept the answer if it's useful.

            – Alexander Dmitriev
            Mar 8 at 10:55











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050152%2fperl-gtk3-add-a-background-image-to-a-window%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0















          I'm trying to add a background image to a window. Using CSS styles,
          it's simple enough, but I only want to add the image to a single
          window, not all of them.




          Just remove the screen provider (and keep the window provider). So comment out the line:



          Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);





          share|improve this answer


















          • 1





            Thanks Håkon, you're the best!

            – lesrol
            Mar 8 at 7:48











          • @lesrol accept the answer if it's useful.

            – Alexander Dmitriev
            Mar 8 at 10:55















          0















          I'm trying to add a background image to a window. Using CSS styles,
          it's simple enough, but I only want to add the image to a single
          window, not all of them.




          Just remove the screen provider (and keep the window provider). So comment out the line:



          Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);





          share|improve this answer


















          • 1





            Thanks Håkon, you're the best!

            – lesrol
            Mar 8 at 7:48











          • @lesrol accept the answer if it's useful.

            – Alexander Dmitriev
            Mar 8 at 10:55













          0












          0








          0








          I'm trying to add a background image to a window. Using CSS styles,
          it's simple enough, but I only want to add the image to a single
          window, not all of them.




          Just remove the screen provider (and keep the window provider). So comment out the line:



          Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);





          share|improve this answer














          I'm trying to add a background image to a window. Using CSS styles,
          it's simple enough, but I only want to add the image to a single
          window, not all of them.




          Just remove the screen provider (and keep the window provider). So comment out the line:



          Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 22:09









          Håkon HæglandHåkon Hægland

          16.3k124393




          16.3k124393







          • 1





            Thanks Håkon, you're the best!

            – lesrol
            Mar 8 at 7:48











          • @lesrol accept the answer if it's useful.

            – Alexander Dmitriev
            Mar 8 at 10:55












          • 1





            Thanks Håkon, you're the best!

            – lesrol
            Mar 8 at 7:48











          • @lesrol accept the answer if it's useful.

            – Alexander Dmitriev
            Mar 8 at 10:55







          1




          1





          Thanks Håkon, you're the best!

          – lesrol
          Mar 8 at 7:48





          Thanks Håkon, you're the best!

          – lesrol
          Mar 8 at 7:48













          @lesrol accept the answer if it's useful.

          – Alexander Dmitriev
          Mar 8 at 10:55





          @lesrol accept the answer if it's useful.

          – Alexander Dmitriev
          Mar 8 at 10:55



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050152%2fperl-gtk3-add-a-background-image-to-a-window%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович