How to transmit value using button

More
5 years 9 months ago #194937 by aleksamc
I've created keyboard using this topic in PyQtPyvcp.

The source value is "displayLabel" value of type QLabel.
I want to transmit this value using some button to type HalQSpinbox with some name.

So in short in differentwords:
I want to use touch screen, so I created keyboard.
I want to move value from keyboard to HalQSpinbox.
There are will be few HalQSpinbox and for each one will be button.
I imagine it like this (in mainwindow.py):
Code:
self.wr_len.clicked.connect(self.WriteLength) #for button wr_len def WriteLength(self,button): text = self.displayLabel.text() self.stone_length.value(text) << I get error "TypeError: value(self): too many arguments"

How I should finnish it?

Please Log in to join the conversation.

More
5 years 9 months ago #194984 by BigJohnT
You need to convert the text to a number with for example int() and it value IIRC returns the value not set the value. You need to use setValue(). You might also do some checking to make sure the text is a digit...

JT

Please Log in to join the conversation.

More
5 years 9 months ago #195012 by aleksamc
Thanks it's work, BigJongT.

I wrote such code:
Code:
self.wr_len.clicked.connect(self.WriteLength) def WriteLength(self,button): if len(self.displayLabel.text()) >0: text = int(self.displayLabel.text()) if text > 0: self.stone_length.setValue(text) else: self.stone_length.setValue(0)

Now I wonder, I have 4 such buttons, with this code and I needto copy this code for each button. My knowledge in Python vanish to zero. But I studied C++ a lone time ago and there was arguments.
How to write arguments in this code in such way that I could change "stone_length" to arg and to use it with different buttons?

After some time
I see that int() doesn't converts '3.3' to integer, I get eror

ValueError: invalid literal for int() with base 10: '34.4'

Please Log in to join the conversation.

Time to create page: 0.095 seconds
Powered by Kunena Forum