logo
down
shadow

Loop to define buttons in Perl / Tkx


Loop to define buttons in Perl / Tkx

By : Kaleb Homes
Date : November 18 2020, 01:01 AM
wish of those help Actually, you just have to call the command via reference and the argument not being referenced.
code :
$Widg{".fButton.bRun$id"}=$Widg{".fButton"}->new_ttk__button(-text => $rh_measure->{'descr'}, -command => [\&wrapper, $id]);


Share : facebook icon twitter icon
Foreach loop to create 100 buttons, painting all buttons at same time as to prevent flicker

Foreach loop to create 100 buttons, painting all buttons at same time as to prevent flicker


By : GoodTerry
Date : March 29 2020, 07:55 AM
Hope that helps Sadly, WinForms does not like to have too many controls, especially when you get into the hundreds. You can never have each control paint at the same time since each control will send its own paint message to windows.
I think the best way to approach a game board like MineSweeper is to just use one control and draw the grid of buttons.
code :
public class Mine {
  public Rectangle Bounds { get; set; }
  public bool IsBomb { get; set; }
  public bool IsRevealed { get; set; }
}
public class MineSweeperControl : Panel {
  private int columns = 16;
  private int rows = 12;
  private Mine[,] mines;

  public MineSweeperControl() {
    this.DoubleBuffered = true;
    this.ResizeRedraw = true;

    // initialize mine field:
    mines = new Mine[columns, rows];
    for (int y = 0; y < rows; ++y) {
      for (int x = 0; x < columns; ++x) {
        mines[x, y] = new Mine();
      }
    }
  }

  // adjust each column and row to fit entire client area:
  protected override void OnResize(EventArgs e) {
    int top = 0;
    for (int y = 0; y < rows; ++y) {
      int left = 0;
      int height = (this.ClientSize.Height - top) / (rows - y);
      for (int x = 0; x < columns; ++x) {
        int width = (this.ClientSize.Width - left) / (columns - x);
        mines[x, y].Bounds = new Rectangle(left, top, width, height);
        left += width;
      }
      top += height;
    }
    base.OnResize(e);
  }

  protected override void OnPaint(PaintEventArgs e) {
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
    for (int y = 0; y < rows; ++y) {
      for (int x = 0; x < columns; ++x) {
        if (mines[x, y].IsRevealed) {
          e.Graphics.FillRectangle(Brushes.DarkGray, mines[x, y].Bounds);
        } else {
          ControlPaint.DrawButton(e.Graphics, mines[x, y].Bounds, 
                                  ButtonState.Normal);
        }
      }
    }
    base.OnPaint(e);
  }

  // determine which button the user pressed:
  protected override void OnMouseDown(MouseEventArgs e) {
    for (int y = 0; y < rows; ++y) {
      for (int x = 0; x < columns; ++x) {
        if (mines[x, y].Bounds.Contains(e.Location)) {
          mines[x, y].IsRevealed = true;
          this.Invalidate();
          MessageBox.Show(
            string.Format("You pressed on button ({0}, {1})",
            x.ToString(), y.ToString())
          );
        }
      }
    }
    base.OnMouseDown(e);
  }
}
Running a shell command in a perl loop, using a variable from the perl loop

Running a shell command in a perl loop, using a variable from the perl loop


By : anm
Date : March 29 2020, 07:55 AM
hope this fix your issue You can do it in several ways, depending on what exactly is needed. Generally, this involves use of system, backticks (with operator form qx), or open. There is also a number of great modules for it.
The qx returns its STDOUT to the program. If you need it assign it to a variable.
code :
for my $i (0..9) {
    my $cmd = "external-command $i";
    my $cmdout = qx($cmd);             # needs error checking ($?)
    print $cmdout;                     # process as needed
}
my $cmd = "external-command $i 2>&1";
for my $i (0..9) {
    my $cmd = "external-command $i";
    my $ret = system($cmd);
    if ($ret != 0) {
        warn "Error running $cmd: $ret";
        # interrogate further, see documentation for 'system'
    }
}
Creating PyQt5 buttons in a loop: all buttons trigger the same callback

Creating PyQt5 buttons in a loop: all buttons trigger the same callback


By : dadi
Date : March 29 2020, 07:55 AM
like below fixes the issue I do not understand what type of structure is matrix, but I think it is equivalent to a list of dictionaries.
The problem is that you must pass as an argument to the lambda function assigning it, the clicked signal takes as a parameter a Boolean value that indicates that if the button is checked or not (by default this property is disabled so that this value is false), you must add another parameter.
code :
class App(QMainWindow):
    def launch(self, filepath):
        subprocess.run(filepath)

    def __init__(self):
        super(App, self).__init__()

        matrix = [{"path": "path1", "setIcon": "icon1", "posx": 0, "posy": 0}, 
        {"path": "path2", "setIcon": "icon2", "posx": 0, "posy": 150},
        {"path": "path3", "setIcon": "icon3", "posx": 0, "posy": 300}]

        for value in matrix:

            filepath = value['path']
            icon =  value['setIcon']
            posx = value['posx']
            posy = value['posy']

            btn = QToolButton(self)
            btn.setIcon(QIcon(icon))
            btn.setIconSize(QSize(64, 64))
            btn.resize(100, 100)
            btn.move(posx, posy)
            btn.clicked.connect(lambda checked, arg=filepath: self.launch(arg))

        self.initUI()

    def initUI(self):
        self.setGeometry(150, 150, 1250, 650)
        self.setWindowTitle('LinuxLauncher')
        self.show()
Define Perl while() = each {} loop with inline hash

Define Perl while() = each {} loop with inline hash


By : rmn
Date : March 29 2020, 07:55 AM
I wish this help you A list/comma operator in scalar context evaluates to the result of the last item evaluated in scalar context. That means
code :
each %{ apple => "red", orange => "orange", grape  => "purple" }
each %{ "purple" }
each %{ { apple  => "red", orange => "orange", grape  => "purple" } }
for (
   [ apple  => "red"    ],
   [ orange => "orange" ],
   [ grape  => "purple" ],
) {
   my ($key, $val) = @$_;
   ...
}
use List::Util qw( pairs );

for (pairs(f())) {
   my ($key, $val) = @$_;
   ...
}
{
   my @kvs = f();
   while ( my ($key, $val) = splice(@kvs, 0, 2) ) {
      ...
   }
}
for (
   my @kvs = f();
   my ($key, $val) = splice(@kvs, 0, 2);
) {
   ...
}
Buttons are showing all the elements or nothing when using a foreach loop.Need to set individual targets for buttons

Buttons are showing all the elements or nothing when using a foreach loop.Need to set individual targets for buttons


By : Audee Mirza
Date : March 29 2020, 07:55 AM
To fix the issue you can do You are currently hiding and showing the #videos element which contains all videos when a button is clicked.
You instead need to relate the clicked button to its video. You can do this by index to keep the logic DRY.
code :
$('.button').click(function() {
  $('.video').hide().eq($(this).index()).show();
});
.video { display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="buttons">
  <button class="button">1</button>
  <button class="button">2</button>
  <button class="button">3</button>
</div>

<div id="videos">
  <div class="video">Pretend I'm a &lt;video /&gt; #1</div>
  <div class="video">Pretend I'm a &lt;video /&gt; #2</div>
  <div class="video">Pretend I'm a &lt;video /&gt; #3</div>
</div>
Related Posts Related Posts :
  • Any way to set keepalive in DBI connect method in Perl
  • Perl script does not recognize paths which contains environment variables
  • How to stop Runaway Perl Process
  • Scoping variables in a Perl Test::More .t file
  • Perl Sort Array
  • Content-Type setting for .MTS files
  • Seek function not working in perl
  • Perl syntax error printing list index
  • perl matching syntax with mail filter
  • Error Handling Using Perl Tkx
  • Perl : calculation of time in format hh:mm:ss,sss
  • Remove element from array containing empty or whitespace character in Perl
  • Running an external command in Perl / Tkx without blocking the GUI (Windows)
  • Passing multiple values to a Perl program in a single command line argument
  • perl Parallel::ForkManager stuck in this script?
  • Unable to escape @ sign in perl
  • Why can't the Opsview_rest Perl script not find the OPSVIEW_URL_PREFIX Environment variable using $ENV{var} while it has
  • Get http-response header with Perl's File::Fetch
  • Perl Get the web content then writing it as a text file
  • perl $CGI::POST_MAX all parameters
  • Perl Foreach until loop
  • login failed to remote host - prompt does not match at /usr/lib/perl5/site_perl/5.10.0/Net/Appliance/Session/Transport.p
  • How is a literal list having one element represented unambiguously in perl?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org