#python #kivy
Вопрос:
Я пытаюсь привязать кнопку «Удалено» к всплывающему окну в приложении Kivy с помощью Python. Тем не менее, я продолжаю получать ошибку:
«box.add_widget(Кнопка(«Удалено», on_press=pop.отклонить)) Ошибка типа: init() принимает 1 позиционный аргумент, но было дано 2″
Ниже приведен фрагмент моего кода.
Код на Python
class MyMainApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.data_tables = None
self.slider = None
self.date_selected = None
self.txt = "0"
def build(self):
self.kv = Builder.load_file("main1.kv")
return self.kv
######## Screen 3 ######
def add_datatable(self):
count = 1
condition = "Bad" # MACHINE LEARNING: LOAD IN TOOL'S CONDITION HERE!!
self.data_tables = MDDataTable(pos_hint={"center_x": 0.5, "center_y": 0.5},
size_hint=(0.545, 0.57),
check = True,
rows_num = 5,
use_pagination = True,
pagination_menu_height = "240dp",
column_data=[
("No.", dp(25)),
("Tools",dp(28)),
("Slot Number", dp(26)),
("Condition", dp(26))
],
row_data=[
(count, "Kuglen", "1", condition),
("", "", "", "")
]
)
if condition == "Bad":
print("Bad tool")
tool_img = "Capture.png"
box = BoxLayout(orientation="vertical", padding=(10))
pop = Popup(title="Faulty tool detected", auto_dismiss=True, content=Image(source=tool_img),
size_hint=(None,None), size=(450,520))
box.add_widget(Button("Removed", on_press=pop.dismiss)) ##The part with error
pop.open()
self.data_tables.bind(on_check_press=self.check_press) #Create a function check_press
self.data_tables.bind(on_row_press=self.row_press)
self.root.ids.data_scr.ids.data_layout.add_widget(self.data_tables)
def change_screen(self, screen: str):
self.root.current = screen
def check_press(self, instance_table, current_row): current_row: has the values of rows that have been pressed
print(instance_table, current_row)
def row_press(self, instance_table, instance_row):
print(instance_table, instance_row)
Комментарии:
1. Если «Удалено» должно быть текстом кнопки, то вам нужно передать это как
text="Button"
.2. Ах да … это часть ошибки. Однако после добавления «текста» я все еще не могу связать кнопку «Удалено» с всплывающим экраном.