I need to develop GUI application for robot and iâm facing this issue.
Code snippet:
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.graphics import Color, Rectangle
kivy.require(â2.0.0â)
class RobotTeachPendant(App):
def init(self, **kwargs):
super(RobotTeachPendant,self).init()
self.joint_values = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
self.records =
self.labels = {} # Store references to joint labels
def increase_value(self, joint_index):
self.joint_values[joint_index] += 1
self.update_label(joint_index)
def decrease_value(self, joint_index):
self.joint_values[joint_index] -= 1
self.update_label(joint_index)
def reset_values(self):
self.joint_values = [0, 0, 0, 0, 0, 0, 0]
for i in range(7):
self.update_label(i)
def add_record(self):
x = self.joint_values[0]
y = self.joint_values[1]
z = self.joint_values[2]
self.records.append((x, y, z))
print(f"Added record: ({x}, {y}, {z})")
def update_label(self, joint_index):
label = self.labels[joint_index]
label.text = str(self.joint_values[joint_index])
def build(self):
root = GridLayout(cols=1, spacing=10, padding=[10, 20])
with root.canvas.before:
Color(0.95, 0.95, 0.95, 1) # Set background color
self.rect = Rectangle(pos=root.pos, size=root.size)
for i in range(7):
joint_layout = GridLayout(cols=3, spacing=10, size_hint=(1, None), height=100)
joint_label = Label(id=f"joint_{i+1}_label", text=f"Joint {i+1}:", size_hint=(0.4, 1))
joint_layout.add_widget(joint_label)
minus_button = Button(text="-", size_hint=(0.2, 1))
minus_button.bind(on_release=lambda btn, index=i: self.decrease_value(index))
joint_layout.add_widget(minus_button)
joint_value_label = Label(text="0", size_hint=(0.2, 1))
joint_value_label.bind(size=joint_value_label.setter('text_size'))
joint_value_label.bind(height=joint_value_label.setter('text_size'))
joint_layout.add_widget(joint_value_label)
self.labels[i] = joint_value_label
plus_button = Button(text="+", size_hint=(0.2, 1))
plus_button.bind(on_release=lambda btn, index=i: self.increase_value(index))
joint_layout.add_widget(plus_button)
root.add_widget(joint_layout)
reset_button = Button(text="Reset", size_hint=(1, None), height=40)
reset_button.bind(on_release=lambda btn: self.reset_values())
root.add_widget(reset_button)
record_button = Button(text="Record", size_hint=(1, None), height=40)
record_button.bind(on_release=lambda btn: self.add_record())
root.add_widget(record_button)
return root
if name == âmainâ:
RobotTeachPendant().run()
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
I tried to create a GUI interface with 7 joints buttons to control the movement, a reset button, play button to resume the motion of the bot, record button to fetch the end effectors x,y and z position.
Error message:
Traceback (most recent call last):
File âkivy_event.pyxâ, line 235, in kivy._event.EventDispatcher.init
TypeError: object.init() takes exactly one argument (the instance to initialize)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File âc:\Users\BrindaS\kivy_venv\newapp.pyâ, line 83, in
RobotTeachPendant().run()
File âC:\Users\BrindaS\AppData\Roaming\Python\Python311\site-packages\kivy\app.pyâ, line 955, in run
self._run_prepare()
File âC:\Users\BrindaS\AppData\Roaming\Python\Python311\site-packages\kivy\app.pyâ, line 925, in run_prepare
root = self.build()
^^^^^^^^^^^^
File âc:\Users\BrindaS\kivy_venv\newapp.pyâ, line 51, in build
joint_label = Label(id=f"joint{i+1}_label", text=f"Joint {i+1}:", size_hint=(0.4, 1))
disabledâ, âdisabled_colorâ, âdisabled_outline_colorâ, âellipsis_optionsâ, âfont_blendedâ, âfont_contextâ, âfont_directionâ, âfont_familyâ, âfont_featuresâ, âfont_hintingâ, âfont_kerningâ, âfont_nameâ, âfont_script_nameâ, âfont_sizeâ, âhalignâ, âheightâ, âidsâ, âis_shortenedâ, âitalicâ, âline_heightâ, âmarkupâ, âmax_linesâ, âmipmapâ, âmotion_filterâ, âopacityâ, âoutline_colorâ, âoutline_widthâ, âpaddingâ, âpadding_xâ, âpadding_yâ, âparentâ, âposâ, âpos_hintâ, ârefsâ, ârightâ, âshortenâ, âshorten_fromâ, âsizeâ, âsize_hintâ, âsize_hint_maxâ, âsize_hint_max_xâ, âsize_hint_max_yâ, âsize_hint_minâ, âsize_hint_min_xâ, âsize_hint_min_yâ, âsize_hint_xâ, âsize_hint_yâ, âsplit_strâ, âstrikethroughâ, âstripâ, âtextâ, âtext_languageâ, âtext_sizeâ, âtextureâ, âtexture_sizeâ, âtopâ, âunderlineâ, âunicode_errorsâ, âvalignâ, âwidthâ, âxâ, âyâ]
Debug info
- Streamlit version: (get it with
$ streamlit version
) - Python version: (get it with
$ python --version
) - Using Conda? PipEnv? PyEnv? Pex?
- OS version:
- Browser version:
Requirements file
Kivy MD using python
Links
- Link to my GitHub repo:Brinda-s ¡ GitHub