Python Forum
[Tkinter] Tkinter classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter classes
#1
Hello everyone.

I'm sorry to bother y'all with my stupid questions, but I just can't get some simple stuff and hours of search doesn't help me. :(

I'm trying to create classes for my GUI, so I could initialize main window through "w = Window()", not "w = tk.Tk()".
Window class should hold my default options for the window (i.e. "self.geometry("640x480" and etc.).
Next, I'd like to create inner class in the Window's class - "Form", and then inner classes for buttons and etc. in this form.

Is this the right idea of organizing my GUI?
I'd like to make my code good to understand for others and keep thing organized.
Also, one of the key features that I need is ability to access these elements from any other part of the code after initialization.

I've started to create a Window class and got some problems from the start.

My code:
import tkinter as tk


class Window(tk.Tk()):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)


if __name__ == "__main__":
    w = Window()
    w.mainloop()
Errors:
Quote:Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1758, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1752, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1147, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/operator/PycharmProjects/forms/newforms.py", line 5, in <module>
class Window(tk.Tk()):
File "C:\Users\operator\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2023, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
TypeError: create() argument 2 must be str, not tuple

Thanks in advance for help!
Reply


Messages In This Thread
Tkinter classes - by Gupi - May-24-2019, 11:29 AM
RE: Tkinter classes - by Yoriz - May-24-2019, 12:43 PM
RE: Tkinter classes - by Gupi - May-24-2019, 05:42 PM
RE: Tkinter classes - by Yoriz - May-24-2019, 05:59 PM
RE: Tkinter classes - by Gupi - May-25-2019, 10:39 AM
RE: Tkinter classes - by Yoriz - May-26-2019, 11:59 AM
RE: Tkinter classes - by Gupi - May-26-2019, 01:38 PM
RE: Tkinter classes - by Yoriz - May-26-2019, 02:31 PM
RE: Tkinter classes - by Gupi - May-26-2019, 05:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter & classes Heyjoe 6 3,229 Feb-13-2021, 09:17 PM
Last Post: Heyjoe
  [Tkinter] How to create multilple tabs in tkinter from different classes Rishav 5 18,570 Jul-11-2018, 11:59 AM
Last Post: CCChris91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020