I am having trouble getting the current values from a QTable with QSpinBox & QCOmboBox widgets inserted in the table. I can get the value from Qlineedit, but nothing else except this one widget works. I have tried in several different ways but it keeps returning "None"
class MainWindow(QDialog):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("ptb")
# Main frame
self.main_layout = QVBoxLayout(self)
# Layout with 2 buttons and a radio button, part of main_layout
self.horizontalLayout = QHBoxLayout()
self.main_frame_tab_widget = QTabWidget()
self.main_layout.addWidget(self.main_frame_tab_widget)
self.horizontalLayout = QHBoxLayout()
self.main_layout.addLayout(self.horizontalLayout)
self.load_script_button = QPushButton("Load")
self.horizontalLayout.addWidget(self.load_script_button)
self.load_script_button.clicked.connect(self.load_script_button_clicked)
self.main_frame_tab_widget.addTab(self.targeting_tab(), "Targeting")
def load_script_button_clicked(self):
model = self.targeting_table.model()
targeting_table_content = {}
for row in range(model.rowCount()):
targeting_table_content[str(model.data(model.index(row, 1)))] = {
'danger': str(model.data(model.index(row, 2))),
'loot': str(model.data(model.index(row, 3))),
'only_if_trapped': str(model.data(model.index(row, 4)))
}
print(targeting_table_content)
def targeting_tab(self):
targeting_tab = QWidget()
# Main targeting tab vertical layout, which contains 2 other sublayouts
targeting_tab_main_layout = QHBoxLayout()
# Sub vertical layout containing a horizontal layout with 2 buttons and a table bellow the VBox
inner_left_vertical_layout = QVBoxLayout()
targeting_tab_main_layout.addLayout(inner_left_vertical_layout)
# Sub horizontal layout containing 2 buttons
inner_left_vertical_layouts_sub_horizontal_box = QHBoxLayout()
inner_left_vertical_layout.addLayout(inner_left_vertical_layouts_sub_horizontal_box)
# Adding creature
self.add_creature_button = QPushButton("Add creature")
inner_left_vertical_layouts_sub_horizontal_box.addWidget(self.add_creature_button)
self.add_creature_button.clicked.connect(self.add_creature_to_targeting_button_clicked)
# Deleting creature
self.delete_creature_button = QPushButton("Delete creature")
inner_left_vertical_layouts_sub_horizontal_box.addWidget(self.delete_creature_button)
self.delete_creature_button.clicked.connect(self.delete_creature_button_clicked)
self.targeting_table = QTableWidget()
self.targeting_table.setColumnCount(4)
self.targeting_table.setHorizontalHeaderLabels(['Name', 'Danger', 'Loot', 'Only if trapped'])
inner_left_vertical_layout.addWidget(self.targeting_table)
targeting_tab.setLayout(targeting_tab_main_layout)
return targeting_tab
def add_creature_to_targeting_button_clicked(self):
row_count = self.targeting_table.rowCount()
self.targeting_table.insertRow(row_count)
self.targeting_table.setItem(row_count, 0, QTableWidgetItem("input_mob_name"))
self.targeting_table.setCellWidget(row_count, 1, QSpinBox())
loot_combo_box = QComboBox()
loot_combo_box.addItems(["Yes", "No"])
self.targeting_table.setCellWidget(row_count, 2, loot_combo_box)
only_if_killed_combo_box = QComboBox()
only_if_killed_combo_box.addItems(["Yes", "No"])
self.targeting_table.setCellWidget(row_count, 3, only_if_killed_combo_box)
def delete_creature_button_clicked(self):
# Shows the number of delected rows bellow
rows = sorted(set(index.row() for index in self.targeting_table.selectedIndexes()))
# Removing the selected rows, if nothing is selected nothing happens
i = 0
for index in sorted(rows):
self.targeting_table.removeRow(index + i)
i = i - 1
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = MainWindow()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
With this when pressing the "load" button I get this result:
{'None': {'danger': 'None', 'loot': 'None', 'only_if_trapped': 'None'}}
If I change the way of obtaining the values from the Qtable the best I get is QlineEdit, but I can not get the Spinbox or the combobox values
The widgets placed above the view have nothing to do with the model, they are independent, so you should not use the model but rather the cellWidget() method to obtain the corresponding widget and through the widget obtain the information.
targeting_table_content = []
for row in range(self.targeting_table.rowCount()):
name = self.targeting_table.item(row, 0).text()
danger = self.targeting_table.cellWidget(row, 1).value()
loot = self.targeting_table.cellWidget(row, 2).currentText()
only_if_trapped = self.targeting_table.cellWidget(row, 3).currentText()
targeting_table_content.append(
{
"name": name,
"danger": danger,
"loot": loot,
"only_if_trapped": only_if_trapped,
}
)
print(targeting_table_content)
Related
I want to use QtreeView to organize the data shown by a QComboBox. As you can see in my example, creating the box and setting up data works so far.
But my problem is, that the combobox itself only shows the first argument and not the whole line. what I want to have is, that there is shown the whole row, not only the first item of the row.
Is this maybe related to the fact, that each cell is selectable? Do I have to prohibit to select items at the end of the tree branch?
How can I achieve this while adding the elements to the QtreeView-data?
minimal example:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
data = [['a','b','c'],['d','e','f'],['g','h','i']]
class MainWindow(QMainWindow):
dispatcher = 0
def __init__(self):
super().__init__()
# buil UI
self.init_ui()
def init_ui(self):
# layout
self.box_window = QVBoxLayout()
# content
model = QStandardItemModel(len(data),len(data[0]))
row = 0
for r in data:
col = 0
for item in r:
model.setData(model.index(row, col), item)
col += 1
row += 1
tree_view = QTreeView()
tree_view.setHeaderHidden(True)
tree_view.setRootIsDecorated(False)
tree_view.setAlternatingRowColors(True)
combobox = QComboBox()
combobox.setMinimumSize(250,50)
combobox.setView(tree_view)
combobox.setModel(model)
self.box_window.addWidget(combobox)
self.box_window.addStretch()
# build central widget and select it
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.centralWidget().setLayout(self.box_window)
# show window
self.setGeometry(50,50,1024,768)
self.setWindowTitle("Test")
self.show()
def main():
app = QApplication(sys.argv)
main_window = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
A possible solution is to concatenate the texts in the row and set as the text to be painted:
class ComboBox(QComboBox):
def paintEvent(self, event):
painter = QStylePainter(self)
painter.setPen(self.palette().color(QPalette.Text))
# draw the combobox frame, focusrect and selected etc.
opt = QStyleOptionComboBox()
self.initStyleOption(opt)
values = []
for c in range(self.model().columnCount()):
index = self.model().index(self.currentIndex(), c, self.rootModelIndex())
values.append(index.data())
opt.currentText = " ".join(values)
painter.drawComplexControl(QStyle.CC_ComboBox, opt)
# draw the icon and text
painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
I m able to dynamically add a layout to QHBoxLayout in pyqt , however I m unable to remove them once added.
Main aim is to dynamically add and remove a layout based on the Radio Button selected.
def SearchTab(self):
self.layout = QVBoxLayout()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
self.layout.addItem(button_layout)
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1))
radio_button_1.toggled.connect(lambda :self.UpdateButtonCheck(radio_button_2))
self.setTabText(0,"Search")
self.tab1.setLayout(self.layout)
def SelectButtonCheck(self,b):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.pg_details = pgd.PGDetails()
layout = self.pg_details.returnLayout()
self.layout.addLayout(layout)
def UpdateButtonCheck(self,b):
if b.text() == "Update":
if b.isChecked():
print(b.text()+ " is selected")
for i in range(self.layout.count()):
print(self.layout.itemAt(i))
temp_layout = self.layout.itemAt(i)
widget = temp_layout.widget()
temp_layout.removeItem(temp_layout)
if widget is not None:
widget.deleteLater()
Initial Screen-
Currently I m able to add the layout when "Search" Radio Button is selected --
But Nothing happens when I select "Update" RadioButton
Also find the layouts that have been added-
for i in range(self.layout.count()):
print(self.layout.itemAt(i))
<PyQt5.QtWidgets.QHBoxLayout object at 0x1180ec438>
<PyQt5.QtWidgets.QFormLayout object at 0x1180ff828>
Layouts are being added but not getting removed.
Any leads would be helpful , in what I m missing here
I was able to solve this. Took me a while but understood what is the arrangement of widgets within the layouts.
I assumed removing the layout will cascade delete the widgets itself.
I used the below function to remove the layout and its widgets corresponding to it.
def SearchTab(self):
self.layout = QVBoxLayout()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
self.layout.addItem(button_layout)
#createDB()
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1,self.layout))
radio_button_1.toggled.connect(lambda :self.UpdateButtonCheck(radio_button_2,self.layout))
#layout.addRow("Address",QLineEdit())
self.setTabText(0,"Search")
update_layout = QHBoxLayout()
#update_layout.set
#update_btn = QDialogButtonBox(QDialogButtonBox)
#update_btn.setAlignment(Qt.AlignBottom)
update_layout.setAlignment(QtCore.Qt.AlignTop)
update_btn = QPushButton('Update')
reset_btn = QPushButton('Reset')
#self.layout.addRow(update_layout)
update_layout.addWidget(update_btn)
update_layout.addWidget(reset_btn)
update_btn.clicked.connect(self.createDB)
self.tab1.setLayout(self.layout)
def SelectButtonCheck(self,b,stacklayout):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.pg_details = pgd.PGDetails()
layout = self.pg_details.returnLayout()
self.layout.addLayout(layout)
def removeLayout(self,layout):
for i in range(layout.count()):
temp_layout = layout.itemAt(i)
if temp_layout is not None:
widget = temp_layout.widget()
if widget is not None:
widget.deleteLater()
else:
return
if temp_layout.layout() is not None:
self.removeLayout(temp_layout.layout())
def removeFormLayout(self,layout):
if layout is not None:
for i in range(layout.count()):
temp_layout = layout.itemAt(i)
if isinstance(temp_layout.layout(),type(QFormLayout())):
self.removeLayout(temp_layout.layout())
else:
next
else:
return
def UpdateButtonCheck(self,b,stacklayout):
if b.text() == "Update":
if b.isChecked():
print(b.text()+ " is selected")
self.removeFormLayout(stacklayout)
The removeFormLayout function picks out the formlayout that I added with the Search radio button and removeLayout removes all the widgets under it as well.
Open to suggestions and improvements in the method used, I tried it with a couple of layout removals other then FormLayout as well. Currently it is working fine.
Also is anybody aware of how to align the HBoxLayout at the top , the radio button starts from the middle again , I want to align them at the top of the screen
Another way is to do the following. QWidget and thus QGroupBox have a show/hide option.
Note, its best to always hide first, otherwise things get wonky
I have a test function that has the following control logic
if isOn:
self.gb1.hide()
self.gb2.show()
else:
self.gb2.hide()
self.gb1.show()
I created a layout that contains both group boxes above. see the sample logic below. I am sure there is a way to do this without storing the variables in the window class.
def create_layout(self):
ly = QHBoxLayout()
self.gb1 = self.create_gb_test1()
self.gb2 = self.create_gb_test2()
ly.addWidget(self.gb1)
ly.addWidget(self.gb2)
return ly
def create_gb_test1(self):
my_name = inspect.currentframe().f_code.co_name
gb = QGroupBox("Find")
btn_find = QPushButton()
ly_horiz = QHBoxLayout()
ly_horiz.addWidget(QLabel("Find:"))
ly_horiz.addWidget(QLineEdit("Some Text", ))
ly_horiz.addWidget(btn_find)
self.ly_find_only = ly_horiz
gb.setLayout(ly_horiz)
return gb
def btn_open_click(self):
pass
def create_gb_test2(self):
my_name = inspect.currentframe().f_code.co_name
gb = QGroupBox("View")
btn_open = QPushButton
cbo = QComboBox()
cbo.addItems(['a', 'b'])
ly_horiz = QHBoxLayout()
ly_horiz.addWidget(QLabel("Find:"))
ly_horiz.addWidget(cbo)
ly_horiz.addWidget(btn_open)
self.ly_find_only = ly_horiz
gb.setLayout(ly_horiz)
return gb
So I'm trying to get a grip on Qt (more specifically, Pyqt), and I want to create a simple feedback form. It should have
a title
a name ('author')
a message
a send and a cancel button
Let's try without the buttons, first (the App class just provides a button to create a popup. the question concerns the Form class below it):
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QDesktopWidget,\
QHBoxLayout, QVBoxLayout, QGridLayout,\
QPushButton, QLabel,QLineEdit, QTextEdit,\
qApp
from PyQt5.QtGui import QIcon
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'PyQt5 Layout Demo'
self.popup = None
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setWindowIcon(QIcon('imgs/python3.png'))
formButton = QPushButton("show form")
formButton.clicked.connect(self.showPopup)
formBox = QHBoxLayout()
formBox.addWidget(formButton)
formBox.addStretch(1)
vbox = QVBoxLayout()
vbox.addLayout(formBox)
vbox.addStretch(1)
# self.setLayout(vbox) # would work if this was a QWidget
# instead, define new central widget
window = QWidget()
window.setLayout(vbox)
self.setCentralWidget(window)
self.center(self)
self.show()
#staticmethod
def center(w: QWidget):
qr = w.frameGeometry() # get a rectangle for the entire window
# center point = center of screen resolution
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp) # move center of rectangle to cp
w.move(qr.topLeft()) # move top-left point of window to top-let point of rectangle
def showPopup(self):
if self.popup is None:
self.popup = Form(self)
self.popup.setGeometry(10, 10, 300, 400)
self.center(self.popup)
self.popup.show()
class Form(QWidget):
def __init__(self, main):
super().__init__()
self.initUI()
self.main = main
def initUI(self):
self.setWindowTitle('Feedback')
self.setWindowIcon(QIcon('imgs/python3.png'))
title = QLabel('Title')
author = QLabel('Author')
message = QLabel('Message')
titleEdit = QLineEdit()
authorEdit = QLineEdit()
messageEdit = QTextEdit()
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit,1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit,2, 1)
grid.addWidget(message, 3, 0)
grid.addWidget(messageEdit, 4, 0, 6, 0)
self.setLayout(grid)
# probably should delegate to self.main, but bear with me
def send(self):
self.main.popup = None
self.hide()
def cancel(self):
self.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Ok, looks about right. There's a bit too much spacing in-between the line edits and the text edit, but since I want to add some buttons below it, that should be be a problem.
So I add:
sendBtn = QPushButton("send")
cancelBtn = QPushButton("cancel")
sendBtn.clicked.connect(self.send)
cancelBtn.clicked.connect(self.cancel)
grid.addWidget(sendBtn, 7, 1)
grid.addWidget(cancelBtn, 7, 2)
which yields
Now obviously, I forgot to stretch the title and author line edits to the newly introduced column 2. Easy enough to fix but what really bothers me is the placement of the buttons.
WHY do they show up in the middle of the text edit? I can see how Qt chooses the column size, and why that would lead to the buttons' being of different size, but since the tutorial doesn't actually add buttons to the form, I have no idea how to fix that.
I could, of course, simply add boxes:
sendBtn = QPushButton("send")
cancelBtn = QPushButton("cancel")
sendBtn.clicked.connect(self.send)
cancelBtn.clicked.connect(self.cancel)
btns = QHBoxLayout()
btns.addStretch(1)
btns.addWidget(sendBtn)
btns.addWidget(cancelBtn)
l = QVBoxLayout()
l.addLayout(grid)
l.addLayout(btns)
self.setLayout(l)
With which the popup then actually starts looking closer to something acceptable:
But is there a way to fix this within the grid layout, instead?
You seem to have misunderstood the signature of addWidget. The second and third arguments specify the row and column that the widget is placed in, whilst the third and fourth specify the row-span and column-span.
In your example, the problems start here:
grid.addWidget(message, 3, 0)
grid.addWidget(messageEdit, 4, 0, 6, 0)
where you make the text-edit span six rows and zero columns - which I doubt is what you intended. Instead, you probably want this:
grid.addWidget(message, 3, 0, 1, 2)
grid.addWidget(messageEdit, 4, 0, 1, 2)
which will make the message label and text-edit span the two columns created by the title and author fields above.
Now when you add the buttons, they must have a layout of their own, since the top two rows are already determining the width of the two columns. If you added the buttons directly to the grid, they would be forced to have the same widths as the widgets in the top two rows (or vice versa). So the buttons should be added like this:
hbox = QHBoxLayout()
sendBtn = QPushButton("send")
cancelBtn = QPushButton("cancel")
sendBtn.clicked.connect(self.send)
cancelBtn.clicked.connect(self.cancel)
hbox.addStretch()
hbox.addWidget(sendBtn)
hbox.addWidget(cancelBtn)
grid.addLayout(hbox, 5, 0, 1, 2)
I am trying to generate a Dialog with a stacked layout of GridLayout (of CheckBox's) and HLayout. Well, I did. But my grid got big (my HLayout is fine) but now I want a ScrollArea so as to not take up too much real estate. I have tried the following code .... and it generates a scroll view, but the size of the scroll view is the size of a button (the first ofc) in the HLayout. I want the scroll view to be the width of the Dialog, which nominally would be the minimum width of the HLayout. Additionally adding the scroll_view and scroll_viewWidget cause a QLayout exception to be raised, QLayout::addChildLayout: layout "" already has a parent. Any idea's?
class checkboxDialog(QtGui.QDialog) :
def __init__(self, headers, name) :
super(checkboxDialog, self).__init__()
self.checkerLayout = QtGui.QVBoxLayout()
self.checkerLayout.setMargin(1)
self.checkerLayout.setSpacing(2)
self.scroll_view = QtGui.QScrollArea(self)
self.scroll_view.setWidgetResizable(True)
self.scroll_viewWidget = QtGui.QWidget()
self.scroll_viewWidget.setGeometry(QtCore.QRect(0, 0, 600, 400))
self.scroll_view.setWidget(self.scroll_viewWidget)
self.checkerHlayout = QtGui.QHBoxLayout(self.scroll_viewWidget)
checksLayout = QtGui.QGridLayout()
checksLayout.setColumnStretch(90,7)
checksLayout.setMargin(1)
checksLayout.setSpacing(2)
self.cbList = []
index = 0
for row_index in range(90):
for column_index in range(7):
if index > len(headers)-1 : break
checkbox = QtGui.QCheckBox(headers[index][0:8], self)
checkbox.setToolTip("Chanel = {}".format(headers[index]))
self.cbList.append(checkbox)
# Hide the Phase channels for now ... not sure I shoudl even build the CheckBoxes
# But if I dont then the len(cbList) < len(data[0])
if headers[index][-1] == 'p' :
checkbox.hide()
checksLayout.addWidget(checkbox, row_index, column_index)
index += 1
self.checkerHlayout.addLayout(checksLayout)
self.buttonLayout = QtGui.QHBoxLayout()
self.buttonLayout.setMargin(1)
self.buttonLayout.setSpacing(2)
applyButton = QtGui.QPushButton("Apply")
nextButton = QtGui.QPushButton("Next")
nextAllButton = QtGui.QPushButton("NextAll")
prevButton = QtGui.QPushButton("Prev")
prevAllButton = QtGui.QPushButton("PrevAll")
clearButton = QtGui.QPushButton("Clear")
self.buttonLayout.addWidget(applyButton)
self.buttonLayout.addWidget(nextButton)
self.buttonLayout.addWidget(nextAllButton)
self.buttonLayout.addWidget(prevButton)
self.buttonLayout.addWidget(prevAllButton)
self.buttonLayout.addWidget(clearButton)
self.checkerLayout.addLayout(self.checkerHlayout)
self.checkerLayout.addLayout(self.buttonLayout)
self.setLayout(self.checkerLayout)
self.setObjectName(name)
self.setWindowTitle(name)
self.connect(applyButton, QtCore.SIGNAL('clicked()'), self.checked)
self.connect(nextButton, QtCore.SIGNAL('clicked()'), self.next_chn)
self.connect(nextAllButton, QtCore.SIGNAL('clicked()'), self.next_chnAll)
self.connect(prevButton, QtCore.SIGNAL('clicked()'), self.prev_chn)
self.connect(prevAllButton, QtCore.SIGNAL('clicked()'), self.prev_chnAll)
self.connect(clearButton, QtCore.SIGNAL('clicked()'), self.clear_chn)
I think this is what you wanted:
self.w2 = QtGui.QWidget(self)
self.w2.setLayout(self.buttonLayout)
self.checkerLayout.addWidget(self.w2)
self.checkerLayout.addWidget(self.scroll_view)
self.setLayout(self.checkerLayout)
(replacing the block with addLayout statements)
I am trying to add tab for 2 grid layout, but when I ran the code it seems like there is no tab.
I think
wid_inner.tab = QtGui.QTabWidget()
is not adding the tab correctly to the grid
import sys
from PySide import QtGui
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
# setting the outter widget and layout
wid = QtGui.QWidget()
grid = QtGui.QGridLayout()
wid.setLayout(grid)
# setting the inner widget and layout
grid_inner = QtGui.QGridLayout()
wid_inner = QtGui.QWidget()
wid_inner.setLayout(grid_inner)
# add the inner widget to the outer layout
grid.addWidget(wid_inner)
# add tab frame to widget
wid_inner.tab = QtGui.QTabWidget()
# create tab
new_tab = QtGui.QWidget()
grid_tab = QtGui.QGridLayout()
grid_tab.setSpacing(10)
new_tab.setLayout(grid_tab)
new_tab.tab_name_private = "test1"
wid_inner.tab.addTab(new_tab, "test1")
# create tab 2
new_tab2 = QtGui.QWidget()
new_tab2.setLayout(grid_tab)
wid_inner.tab.addTab(new_tab2, "test2")
wid.show()
sys.exit(app.exec_())
Any help would be appreciated thanks
You need to provide the parent to each inner widget, and the tab widget wid_inner.tab was not being added to any layout. This seems a little complicated to establish the layout... Have you considered using QtDesigner?
wid = QtGui.QWidget()
grid = QtGui.QGridLayout(wid)
wid.setLayout(grid)
# setting the inner widget and layout
grid_inner = QtGui.QGridLayout(wid)
wid_inner = QtGui.QWidget(wid)
wid_inner.setLayout(grid_inner)
# add the inner widget to the outer layout
grid.addWidget(wid_inner)
# add tab frame to widget
wid_inner.tab = QtGui.QTabWidget(wid_inner)
grid_inner.addWidget(wid_inner.tab)
# create tab
new_tab = QtGui.QWidget(wid_inner.tab)
grid_tab = QtGui.QGridLayout(new_tab)
grid_tab.setSpacing(10)
new_tab.setLayout(grid_tab)
new_tab.tab_name_private = "test1"
wid_inner.tab.addTab(new_tab, "test1")
# create tab 2
new_tab2 = QtGui.QWidget(wid_inner.tab)
new_tab2.setLayout(grid_tab)
wid_inner.tab.addTab(new_tab2, "test2")
wid.show()
app.exec_()