Python Forum
[Tkinter] Tkinter Class Import Module Issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter Class Import Module Issue
#1
Lightbulb 
I'm trying to keep my code clean by separating the GUI from the logic.

Inside of the 'main.py' file, I'd like to call functions from other files that are imported to build the GUI.

The problem is that I cannot figure out how to build a GUI from the 'main.py' file when I try to call another file as an imported module.

Here's what I have in the 'main.py' file:

from tkinter import *
import create_btn

class Main(Tk):
    def __init__(self):
        super().__init__()
        self.title('Main Window')
        self.geometry('600x400')
        self.eval('tk::PlaceWindow . center')


if __name__ == '__main__':
    app = Main()
    app.mainloop()
And here is what I have in the 'create_btn.py' file:

from tkinter import *

def createBTN(self):
    self.b1 = Button(root, text='B1')
    self.b1.pack()
So, how exactly can I build a simple button from another file that I want to import into the 'main.py', or in other words, how do I get the 'create_btn.py' file to build the button inside of the 'main.py' file? A simple example would be greatly appreciated.
Reply


Messages In This Thread
Tkinter Class Import Module Issue - by AaronCatolico1 - Sep-04-2022, 06:11 PM
RE: Tkinter Class Import Module Issue - by Yoriz - Sep-04-2022, 09:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,498 Dec-14-2022, 08:01 PM
Last Post: deanhystad
  unexplained issue with tkcalender module. cybertooth 8 7,720 Aug-12-2021, 11:00 PM
Last Post: deanhystad
  [Tkinter] Redirecting all print statements from all functions inside a class to Tkinter Anan 1 2,683 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  tkinter moving an class object with keybinds gr3yali3n 5 3,313 Feb-10-2021, 09:13 PM
Last Post: deanhystad
  Super basic tkinter arduino issue Kurta 3 2,445 Jan-07-2021, 05:22 PM
Last Post: deanhystad
Photo tkinter issue mate 4 2,582 Dec-06-2020, 09:03 PM
Last Post: mate
  How to import entire module ? tonycstech 5 3,382 Oct-21-2020, 06:16 AM
Last Post: tonycstech
  Issue in Tkinter with winfo_class() and LabelFrame ReDefendeur 1 2,770 Oct-05-2020, 05:52 AM
Last Post: Jeff900
  [Tkinter] tkinter: after issue edwin6938 1 3,432 Aug-25-2020, 04:37 PM
Last Post: Larz60+
  [Tkinter] Troubles with accessing attr from other class zarize 3 2,666 Aug-20-2020, 06:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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