-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_Qt_image.py
More file actions
66 lines (47 loc) · 1.75 KB
/
Copy pathtesting_Qt_image.py
File metadata and controls
66 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import os
from PySide6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QApplication, QPushButton, QLabel
from PySide6.QtGui import QPixmap
from classdefs.modscaledlabel import ScaledLabel
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Create an instance of the scaled label class:
self.my_label = QLabel()
# Create an instance of QPixmap using the desired image:
self.path_to_png = 'qmark3.png'
my_pixmap = QPixmap(self.path_to_png)
# Display the image inside the label:
self.my_label.setPixmap(my_pixmap)
# Create a button:
my_button = QPushButton()
my_button.setText('Delete .png file')
# Wire the button pressed signal to a function that tries to delete the gif:
my_button.clicked.connect(self.button_clicked)
# Place the label & button in a layout:
layout = QVBoxLayout()
layout.addWidget(self.my_label)
layout.addWidget(my_button)
# Create a placeholder widget to hold the layout.
widget = QWidget()
widget.setLayout(layout)
# Set the central widget of the main window:
self.setCentralWidget(widget)
def button_clicked(self):
# First, try to stop python using the png:
# self.try_to_stop_using_png()
# Then, attempt to delete the .png file:
self.attempt_to_delete_png()
def try_to_stop_using_png(self):
self.my_label.clear()
del self.my_label
pass
def attempt_to_delete_png(self):
# Use os.remove to try to delete the gif file:
os.remove(self.path_to_png)
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec()
print('app finished')
os.remove('qmark3.png')