This is a curiosity question. I have a block of code that executes upon an accepted.connect(). It throws out this error but when I check the results they still work. And from what I understand from button box: upon pressing OK or cancel, the dialog should close on it's own. I haven't even initialized self.buttonBox.canceled.connect but when I push cancel the window closes. When I push OK though the window stays open and gives the following error:
TypeError: accept() missing 2 required positional arguments: 'player' and 'window'
So here's some code:
class UIinit(QtGui.QDialog, UI.Buy_Cargo.Ui_Dialog):
"""The Dialog for initiation"""
def __init__(self, player, window):
super(UIinit, self).__init__()
self.window = window
self.player = player
self.setupUi(self)
#for i in Config.port_prices:
# up = getattr(self, "btn_" + i + "_up")
# up.clicked.connect(partial(self.up, i, player))
# down = getattr(self, "btn_" + i + "_down")
# down.clicked.connect(partial(self.down, i))
# add_price = getattr(self, "H_" + i)
# add_price.setText(i +
# " (" + str(self.player.port.price[i]) + ")")
self.buttonBox.accepted.connect( # the important part
partial(self.accept, player, window))
def accept(self, player, window):
if int(self.V_Total.text()) <= player.money:
for i in player.ship.cargo:
num = int(getattr(self, "V_" + i).text())
player.ship.cargo[i] += num
window.to_shipyard()
dia = UIinit(player, window)
dia.exec_()
I've tried connect(lambda: self.accept(player, window)) and using self.player and self.window as the arguments.