I want to import a script with a simple GUI into my main python script and get this error by executing test.py:
TypeError: init() missing 1 required positional argument: 'root'
Main script: test.py
import input_1
print('before window')
input_1.App()
print('after window')
GUI script: input_1.py
import tkinter as tk
import tkinter.font as tkFont
class App:
def __init__(self, root):
#setting title
root.title("Input stator batch and number")
#setting window size
width=456
...
def GButton_293_command(self):
print("command")
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
root.mainloop()
Questions:
- What do I do wrong? Is there something horribly wrong with my syntax?
- How do I link the GUI-Script to my main script, when it is located in different folder?
CodePudding user response:
In your test.py script, you need to define the inputs for your App class.
Try this:
import input_1
if __name__ == "__main__":
root = tk.Tk()
app = input_1.App(root)
root.mainloop()