@Kostyan4ik

Как решить эту ошибку?

Есть ошибка :
Traceback (most recent call last):
File "c:/Users/Kostyan4ik/Documents/Программы/Python/Проекты/Kivy/main.py", line 55, in
class gridlayout(GridLayout()):
TypeError: __init__() takes 1 positional argument but 4 were given

Помогите пожалуйста решить. Вот код:
import pyautogui
from pygments.lexers import PythonLexer
import os
import subprocess

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.codeinput import CodeInput
from kivy.uix.button import Button
from kivy.config import Config
Config.set('graphics', 'width', '750')
Config.set('graphics', 'height', '500')
Config.set('graphics', 'resizable', '0')

def openfile(instance = None):
    way = pyautogui.prompt("Input dir")
    if way != None:
        with open("info", "w") as i:
                i.write(way)
        with open(way, "r") as f:
            input.text = f.read()
def savefile(instance = None):
    with open("info", "r") as i:
        if i.read() != "":
            with open(i.read(), "w") as f:
                f.write(input.text)
def run(instance = None):
    savefile()
    with open("info", "r") as f:
        command = ["python", f.read()]
        new_window_command = "cmd.exe /c start".split()
        subprocess.check_call(new_window_command + command)
def newfile(instance = None):
    way = pyautogui.prompt("New file")
    if way != None:
        with open(way, "w") as f:
            f.write(input.text)
        with open("info", "w") as i:
            i.write(way)
        with open(way, "r") as f:
            input.text = f.read()

btnrun = Button(text = "Run", size = (75, 25), pos = (0, 475))
btnrun.bind(on_press = run)
btnopen = Button(text = "Open", size = (75, 25), pos = (73, 475))
btnopen.bind(on_press = openfile)
btnsave = Button(text = "Save", size = (75, 25), pos = (146, 475))
btnsave.bind(on_press = savefile)
btnnew = Button(text = "New", size = (75, 25), pos = (219, 475))
btnnew.bind(on_press = newfile)

input = CodeInput(lexer = PythonLexer(), size = (750, 477))

class gridlayout(GridLayout()):
    
    def __init__(self, **kwargs):
        super(gridlayout, self).__init__(**kwargs)
        self.add_widget(input)
        self.add_widget(btnrun)
        self.add_widget(btnopen)
        self.add_widget(btnsave)
        self.add_widget(btnnew)

class main(App):

    def build(self):
        return gridlayout()


if __name__ == '__main__':
    main().run()


Простите, если иногда трудно читать код.

UPD: info - файл который используется вместо глобальной переменной потому что его можно менять из функций.
  • Вопрос задан
  • 156 просмотров
Решения вопроса 1
AlexandrovRoman
@AlexandrovRoman
Python backend developer
Ну во первых вероятнее нужно наследовать от класса, а не от объекта

class gridlayout(GridLayout):

И вероятнее всего это

super(gridlayout, self).__init__(**kwargs)

Нужно заменить на
super().__init__(**kwargs)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы