473,513 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 6668

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

Similar topics

21
7873
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 be done? if yes, then how? Also, how do I link a command button click to the opening of files within the cd, i.e. word, excel and access files? ...
1
2351
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 ideas, and maybe write up an article later. AOP is not just buzzword. It's not just callback, it's not just Ruby's MixIn, it's not just Python's...
4
2293
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 organization, and I'm donating the work. Haven't done Web work in a while, and things have changed since I last did anything of this magnitude. I'm...
2
1587
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 what I have been trying to work out for these functions but can't get them to fully work out for me. information: A function to access an element...
2
1969
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 computer knowledge at all! And they also have outdated, old browsers, slow modems, old computers, etc. So I need to keep this as simple as possible...
66
5279
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 occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of...
1
1189
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 general consensus on how to proceed from here. Thank you in advance for anyone who takes the time to reply... I am upgrading a VB4.0 program...
232
13066
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an...
6
1490
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 dialog box, but that this button is greyed out because the user hasn't entered their username yet. Now let's say the user writes some code that sends a...
4
1567
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 broken up into smaller programs/modules that can be called from the main program. I understand that I would need to, via a Click Button to close one...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.