473,287 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Python:how to create a set of buttons on top of a label in my main window

Brand new to Python. I am looking on advice on how to create a set of buttons on top of a label in my main window.

These 5-6 buttons will be chosen from 3 excel sheets based by the user values set in a QSpinBox (values 1-20) and a QSlider (values 1-3). Then the buttons will be generated by a QButton and each button can be closed after user interaction.

IE: A user setting of QSpinBox "1" will pull randomly from row 1 values and QSLider "1" will select the specific sheet one. Next when QButton is pressed the 5-6 buttons will populate. Clicking on the buttons will generate a note which then can be closed and that button disappears.

So far I have my main window and I can load a user image into a label which I want the random buttons to generate over

Expand|Select|Wrap|Line Numbers
  1. from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QLabel, QFileDialog
  2. from PyQt5 import uic
  3. from PyQt5.QtGui import QPixmap
  4. import sys
  5.  
  6. class UI(QMainWindow):
  7.     def __init__(self):
  8.         super(UI, self).__init__()
  9.  
  10.         # Load the ui file
  11.         uic.loadUi("TEST2.ui", self)
  12.  
  13.         # Define widgets
  14.         self.button = self.findChild(QPushButton, "pushButton")
  15.         self.label = self.findChild(QLabel, "label")
  16.  
  17.         # Click The Dropdown Box
  18.         self.button.clicked.connect(self.clicker)
  19.  
  20.         # Show The App
  21.         self.show()
  22.  
  23.     def clicker(self):
  24.         fname = QFileDialog.getOpenFileName(self, "Open File", "c:\\gui\\images", "All Files (*);;PNG Files (*.png);;Jpg Files (*.jpg)")
  25.  
  26.         # Open The Image
  27.         if fname:
  28.             self.pixmap = QPixmap(fname[0])
  29.             # Add Pic to label
  30.             self.label.setPixmap(self.pixmap)
  31.  
  32. # Initialize The App
  33. app = QApplication(sys.argv)
  34. UIWindow = UI()
  35. app.exec_()
  36.  
Aug 13 '22 #1
0 6657

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Roy Riddex | last post by:
Hi I'm wanting to create a cd-rom which boots automatically when it's inserted into the computer. What I hope to achieve is for a VB6 program to run automatically when the cd boots up. Can this...
1
by: Hung Jung Lu | last post by:
Hi, I have been looking into AOP (Aspect-Oriented Programming) for sometime, now. I frankly don't like the syntax of any of the approaches I have seen so far. I am kind playing around with some...
4
by: Marquisha | last post by:
If this is off-topic, please forgive me. But I thought this might be the perfect spot to get some advice about how to proceed with a project. Working on a Web site design for a nonprofit...
2
by: duncanblacksmithmath | last post by:
I know a lot of you have seen this before but I have worked on the program and have gotten it to work thus far but I need help getting these two functions to work and implementing them. Here is...
2
by: Steve K | last post by:
I got a bit of a problem I like some help on. I'm designing an online training module for people that work in food processing plants. This is my target audience. These workers have little or no...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
1
by: jmar | last post by:
I posted on this topic a while back and received some good responses. However, I have better insight into what I'm looking to do so I am tapping the wealth of experience here again hoping to find a...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
6
by: =?iso-8859-1?q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Usually someone writes a program and guarantees its behaviour so long as people don't deliberately go and try to make it malfunction. For instance, let's say we have a "Proceed" button on the...
4
by: =?Utf-8?B?MjJQb20=?= | last post by:
Hi All, This is all new to me so please be patient with me. What I have is a very large 'Al-In-One' program, not yet complete, that has over 70 Forms/Modules/Classes in it and needs to be...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.