I am trying to make a GUI for already functional python modules as a project. I am new to Tkinter so i used https://stackoverflow.com/a/7557028/10315872 this answer by Bryan Oakley here as a reference for my work with minor changes here and there. The GUI python file here is supposed to get the data from the user and use other python modules PdbHandler and CrdHandler to generate data files which have to be displayed using Tkinter. Attached below is the current progress of the project which is showing an error Attribute error 'Master' object has no attribute '_loadtk'.
File "C:\Users\Dark12Arrow\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2022, in __init__
self._loadtk()
AttributeError: 'master' object has no attribute '_loadtk'
I tried using root=tk.Tk() and the passing root to master as was a similar problem in this query Python Tkinter error object has no attribute .But that shows another error.
File "C:\Users\Dark12Arrow\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2020, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive,
wantobjects, useTk, sync, use)
TypeError: create() argument 1 must be str or None, not Tk
Since the code is still incomplete page two is only a blank page:
import tkinter as tk
import PdbHandler
import CrdHandler
from tkinter import filedialog
filetype=0
class master(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
self.frames[page_name].grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
def NextAction(event):
if choice.get()==0:
print("PDB selected")
filetype=0
controller.show_frame(PageOne)
elif choice.get()==1:
print("CRD Selected")
filetype = 1
controller.show_frame(PageOne)
else:
print("select one atleast")
chosemsg=tk.StringVar()
choice=tk.IntVar()
clabel=tk.Label(self,textvariable=chosemsg)
clabel.grid(row=0,padx=30,pady=10)
chosemsg.set("Chose File type :")
pdbradbutton=tk.Radiobutton(self,text="PDB",variable=choice,value=0)
pdbradbutton.grid(row=1)
crdradbutton=tk.Radiobutton(self,text="CRD",variable=choice,value=1)
crdradbutton.grid(row=2)
nextBttn=tk.Button(self,text="Next", command=lambda: NextAction)
nextBttn.grid(row=4,pady=10,column=5)
class PageOne(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
def OpenAction():
if filetype==0:
self.filename = filedialog.askopenfilename(initialdir="C:\\", title="Select file",
filetypes=(("pdb files", "*.pdb"), ("all files", "*.*")))
PdbHandler.pdbHandler(self.filename)
controller.show_frame(PageTwo)
elif filetype==1:
self.filename = filedialog.askopenfilename(initialdir="C:\\", title="Select file",
filetypes=(("pdb files", "*.pdb"), ("all files", "*.*")))
CrdHandler.crdHandler(self.filename)
controller.show_frame(PageTwo)
else:
print("select one atleast")
filename=tk.StringVar()
choice=tk.IntVar()
clabel=tk.Label(self,textvariable="Choose file")
clabel.grid(row=0,padx=30,pady=10)
nextBttn=tk.Button(self,text="Open", command=lambda: OpenAction)
nextBttn.grid(row=4,pady=10,column=5)
class PageTwo(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
app= master()
app.mainloop()