Could I have used a for loop somehow? - python

Just wondering if there is a way to clean this up a little where its a bunch of lines that only changes a little. This is using python 3.4.3, tkinter, and mysql.connector.
Plantname = tk.StringVar()
self.Plantbox = tk.Entry(self, textvariable=Plantname)
self.Plantbox.grid(row=0, column=0)
self.Name = tk.Label(self, text="Name",width=10)
self.Name.grid(row=1, column=0)
self.Amount = tk.Label(self, text="Amount",width=10)
self.Amount.grid(row=1, column=1)
self.Date = tk.Label(self, text="Date",width=10)
self.Date.grid(row=1, column=2)
self.Planting = tk.Label(self, text="Planting #",width=10)
self.Planting.grid(row=1, column=3)
self.batch = tk.Label(self, text="batch #",width=10)
self.batch.grid(row=1, column=4)
self.Name_2 = tk.Label(self, text="0")
self.Name_2.grid(row=2, column=0)
self.Amount_2 = tk.Label(self, text="0")
self.Amount_2.grid(row=2, column=1)
self.Date_2 = tk.Label(self, text="0")
self.Date_2.grid(row=2, column=2)
full code:
https://pastebin.com/JPjrtdEg

Yes, you can use a loop. There's nothing special about tkinter objects that make them any different than any other python object.
for col, heading in enumerate(("Name", "Amount", "Date", "Planting #", "batch #")):
label = tk.Label(self, text=heading, width=10)
label.grid(row=1, column=col)

Related

How to hide a part of the frame through button pressing

I have a window with two parts. One part is to do some settings. I want to hide it until the user press a setting button. is it possible to hide a part of the frame that contains many widgets?
I have seen many examples to hide a widget in tkinter (eg. pack_forget and grid_forget). In my case, I am trying to hide a part of the frame through a button press (that contains more than one widgets). Any suggestions please
I can't use more than one frames because of some issues.
import tkinter as tk
def startFn():
pass
#fn body
def stopFn():
pass
#fn body
def FnToShow():
pass
#fn body ???
def FnToHide():
pass
#fn body ???
root = tk.Tk()
root.geometry('600x400')
#two containers like this.
#trying to hide container_2 untill the user press settingBtn
container_1 = tk.Frame(root, borderwidth=2, relief="solid")
container_2 = tk.Frame(root, borderwidth=2, relief="solid")
startBtn = tk.Button(container_1, text = "Start", command =startFn)
startBtn.grid(row=4, column=4)
stopBtn = tk.Button(container_1, text = "Stop", command= stopFn)
stopBtn.grid(row=5, column=4)
settingBtn = tk.Button(container_1, text = "Settings", command= FnToShow)
settingBtn.grid(row=6, column=4)
setting_1 = tk.Label(container_2, text = "Setting-1", fg='#000000')
setting_1.grid(row=3, column=10)
setting_2 = tk.Label(container_2, text = "Setting-2", fg='#000000')
setting_2.grid(row=4, column=10)
closeSettingBtn = tk.Button(container_2, text = "close Settings", command= FnToHide)
closeSettingBtn.grid(row=5, column=10)
container_1.pack(side="left", expand=True, fill="x", padx=1, pady=1)
container_2.pack(side="right",expand=True, fill="x", padx=1, pady=1)
root.mainloop()
You could show/hide the entire container_2 using the functions FnToShow and FnToHide:
something like this:
import tkinter as tk
def startFn():
pass
def stopFn():
pass
def FnToShow():
container_2.pack(side="right",expand=True, fill="x", padx=1, pady=1)
def FnToHide():
container_2.pack_forget()
root = tk.Tk()
root.geometry('600x400')
container_1 = tk.Frame(root, borderwidth=2, relief="solid")
container_2 = tk.Frame(root, borderwidth=2, relief="solid")
startBtn = tk.Button(container_1, text="Start", command =startFn)
startBtn.grid(row=4, column=4)
stopBtn = tk.Button(container_1, text="Stop", command= stopFn)
stopBtn.grid(row=5, column=4)
settingBtn = tk.Button(container_1, text="Settings", command= FnToShow)
settingBtn.grid(row=6, column=4)
setting_1 = tk.Label(container_2, text="Setting-1", fg='#000000')
setting_1.grid(row=3, column=10)
setting_2 = tk.Label(container_2, text="Setting-2", fg='#000000')
setting_2.grid(row=4, column=10)
closeSettingBtn = tk.Button(container_2, text="close Settings", command= FnToHide)
closeSettingBtn.grid(row=5, column=10)
container_1.pack(side="left", expand=True, fill="x", padx=1, pady=1)
root.mainloop()

Remove Entry widgets created in a loop

So I am now making a GUI application with tkinter and whatever number I put in the uppermost box, the GUI will automatically add another entry row
When I put 1, and then I try to bigger number such as 3 or 5 it works just fine ,the entry row will show up, the problem is whenever I put number such as 5 and the try to put number less than 5, the entry will still show up instead of
removed
Is there any way that when I put bigger number such as 4 and followed by the less such as 2 and the, the entry from 5 will be removed??
Edit : add code
def choiceone(self):
self.labeln1 = ttk.Label(self, text="1", justify="center")
self.labeln1.grid(row=7, column=1)
self.entry1 = ttk.Entry(self, width=15)
self.entry1.grid(row=7, column=2)
self.entry2 = ttk.Entry(self, width=15)
self.entry2.grid(row=7, column=3)
self.entry3 = ttk.Entry(self, width=15)
self.entry3.grid(row=7, column=4)
self.entry4 = ttk.Entry(self, width=15)
self.entry4.grid(row=7, column=5)
def choicetwo(self):
self.labeln2 = ttk.Label(self, text="2", justify="center")
self.labeln2.grid(row=9, column=1)
self.entry5 = ttk.Entry(self, width=15)
self.entry5.grid(row=9, column=2)
self.entry6 = ttk.Entry(self, width=15)
self.entry6.grid(row=9, column=3)
self.entry7 = ttk.Entry(self, width=15)
self.entry7.grid(row=9, column=4)
self.entry8 = ttk.Entry(self, width=15)
self.entry8.grid(row=9, column=5)
def choicethree(self):
self.labeln3 = ttk.Label(self, text="3", justify="center")
self.labeln3.grid(row=11, column=1)
self.entry9 = ttk.Entry(self, width=15)
self.entry9.grid(row=11, column=2)
self.entry10 = ttk.Entry(self, width=15)
self.entry10.grid(row=11, column=3)
self.entry11 = ttk.Entry(self, width=15)
self.entry11.grid(row=11, column=4)
self.entry12 = ttk.Entry(self, width=15)
self.entry12.grid(row=11, column=5)
class MultiLevel(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = ttk.Label(self, text="Fatigue Failure", font=LARGE_FONT)
label.grid(columnspan=3, sticky="w")
labele1 = ttk.Label(self, text="METHOD 1", font=LARGE_FONT)
labele1.grid(row=1, column=1)
ttk.Separator(self, orient=tk.HORIZONTAL).grid(row=2, columnspan=5, sticky="EW")
labele0 = ttk.Label(self, text="")
labele0.grid(row=3, column=1)
label0 = ttk.Label(self, text="Number of \nStress Level: ", font=MEDIUM_FONT, justify="center")
label0.grid(row=4, column=1)
self.entry0 = ttk.Entry(self, width=15)
self.entry0.grid(row=4, column=2)
button0 = ttk.Button(self, text="OK ", command=lambda: self.ok())
button0.grid(row=4, column=3)
def ok(self):
try:
float(self.entry0.get())
except ValueError:
errormsg("INPUT YOUR NUMBER")
else:
if float(self.entry0.get()) == 1:
choiceone(self)
elif float(self.entry0.get()) == 2:
choiceone(self)
choicetwo(self)
elif float(self.entry0.get()) == 3:
choiceone(self)
choicetwo(self)
choicethree(self)
Everytime you put numer you alway create new Entries in grid but you never remove previous Entries so don't expect that they will magically disappear.
You have to use grid_forget() to hide widget (but not remove from memory), or grid_remove() to remove from grid and from memory.
Now when you put 1 then you create entries in first row, and when you put 3 you create again entries in first row so you have two entries in every cell in first row - one above another - previous entries don't disappear.
BTW: It could be easier if you would keep entries on list - self.entries[0], self.entries[1], etc. or as 2-dimensional list self.entries[row][col].
As #furas said, you need to destroy the existing widgets first:
def ok(self):
try:
float(self.entry0.get())
except ValueError:
errormsg("INPUT YOUR NUMBER")
else:
# remove existing widgets start from row 7
for widget in self.grid_slaves():
if int(widget.grid_info()["row"]) >= 7:
widget.destroy()
if float(self.entry0.get()) == 1:
choiceone(self)
...
PS: As from your code, the concern widgets are put in row 7 and above.
The suggestion is based on your code, but I think you better refactor your code.

why is nothing returned when I invoke .get()

Having trouble setting the file path that is selected by the user and setting to variable. I am able to retrieve the path and set it to display in the entry box but I would like to capture that path and import it into another script. Maybe my logic is flawed here? What am I doing wrong?
import Tkinter
import tkFileDialog
from Tkinter import *
from tkFileDialog import *
class GUI:
def __init__(self, master):
self.master = master
master.title("XML Compare Tool")
master.geometry('700x300')
path1 = StringVar()
path2 = StringVar()
self.bb1 = Button(master, text="Browse", command=lambda: path1.set(askopenfilename()))
self.bb1.grid(row=0, column=0, padx=5, pady=5)
self.bb2 = Button(master, text="Browse", command=lambda: path2.set(askopenfilename()))
self.bb2.grid(row=1, column=0, padx=5, pady=5)
self.confirm = Button(master, text="Confirm", command='')
self.confirm.grid(row=3, column=1, padx=5, pady=5, sticky='')
self.entry1 = Entry(master, width=75, textvariable=path1)
self.entry1.grid(row=0, column=1, columnspan=2, sticky=W)
print path1.get()
self.entry2 = Entry(master, width=75, textvariable=path2)
self.entry2.grid(row=1, column=1, sticky=W)
self.t_label = Label(master, text="Script Output")
self.t_label.grid(row=4, column=1, columnspan=1, sticky='')
self.t_frame = Frame(master, bg="white", height=150, width=600)
self.t_frame.grid(row=5, column=1, columnspan=1, sticky='')
self.t_text = Text(self.t_frame)
root = Tk()
my_gui = GUI(root)
root.mainloop()
You do not need to use a textvariable, you can just use variable = entry1.get(). A Tkinter textvariable is not like a traditional python variable, it is just used for setting the text in an entry.

Tkinter Label Overwrite

I'm using Tkinter to do a small project. Long story short, I want a label to generate some stuff on creation.
Later on, I want to print a label in the same spot but with different text.
I cannot for the life of me figure out how to remove the previous text.
What I wind up with in this example is the text "Does this even work" printed on top of "ALL I WANT IS A VERY LONG AND ANNOYING SENTENCE FOR TESTING"
Thanks!
from Tkinter import *
import pygal
class Application(Frame) :
def __init__(self, root) :
Frame.__init__(self, root)
self.root = root
self.grid()
self.create_widgets()
def create_widgets(self) :
queryLabel = Label(self, text = "Enter your query :")
queryLabel.grid(row=0, column=0, sticky=W)
self.userQuery = StringVar()
qEntry = Entry(self, textvariable=self.userQuery)
qEntry.grid(row=0, column=1, sticky=W)
queryTypeLabel = Label(self,text="Selecting query type: ")
queryTypeLabel.grid(row=2, column=0, sticky=W)
self.searchType = StringVar()
authorButton = Radiobutton( self, text="Author", variable=self.searchType, value="author")
authorButton.grid(row=3,column=0,sticky=W)
memberButton = Radiobutton( self, text="PC Member", variable=self.searchType, value="pcmember")
memberButton.grid(row=3,column=1,sticky=W)
affilButton = Radiobutton( self, text="Affiliation", variable=self.searchType, value="affiliation")
affilButton.grid(row=3,column=2,sticky=W)
self.conference = BooleanVar()
confCheck = Checkbutton(self, text="Select Conference?", variable = self.conference)
confCheck.grid(row=4,column=0,sticky=W)
self.conferenceName = StringVar()
self.conferenceName.set('No Preference')
confDropDown = OptionMenu(self, self.conferenceName, *conferenceOptions)
confDropDown.grid(row=4,column=1,sticky=W)
submit_button = Button( self, text="Submit", command = self.reveal)
submit_button.grid(row=5, column = 0, sticky = W)
#self.graphics_button = Button( self, text="I want Statistics!", command=self.graphics)
#self.graphics_button.grid(row=5, column = 1, sticky= W)
label1 = Label(root, text="ALL I WANT IS A VERY LONG AND ANNOYING SENTENCE FOR TESTING")
label1.grid(row=6, column=0, columnspan=5, sticky=W)
def reveal(self) :
#root.submit_button.grid_destroy()
self.label1 = Label(root, text="Does this even work?")
self.label1.grid(row=6, column=0, columnspan=5, sticky=W)
Bunch of MySQL stuff deleted
### Launch the UI
root = Tk()
root.geometry("800x800+300+300")
app = Application(root)
In reveal, you're creating a new Label which you grid in the same place as the previous label. What you want to do is use this:
# Make label1 an attribute of self to be able to reference it in reveal
self.label1 = Label(root, text="ALL I WANT IS A VERY LONG AND ANNOYING SENTENCE FOR TESTING")
self.label1.grid(row=6, column=0, columnspan=5, sticky=W)
def reveal(self) :
#root.submit_button.grid_destroy()
# Do not create a new Label, but change the existing one
self.label1.config(text="Does this even work?")
I had the exact same issue, and it was incredibly annoying--trying both grid_destroy() and grid_forget(). Neither worked. What worked for me was to call the label 2 times, the first time with many spaces, and the second with what I actually wanted to show. This way, the label content is overwriting spaces, not old content. I know this is not the best way to do this, but it gets me the result I want without a headache:
NumAssetsLabel = tk.Label(self, text="Num of Assets: ", font=('Helvetica', 10))
NumAssetsLabel.grid(row=9, column=3, pady=20, padx=10, sticky="w", columnspan=2)
NumAssetsLabel = tk.Label(self, text="Num of Assets: %s"%runCheck, font=('Helvetica', 10))
NumAssetsLabel.grid(row=9, column=3, pady=20, padx=10, sticky="w", columnspan=2)
Note that I have columnspan=2, to make sure that the number of spaces does not impact the grid.

Issues with layout management in Tkinter Python application

I am having a real issue with a little Tkinter program I'm making in Python as a frontend to my own CMS, regarding layout of the controls on the window. I am new to Tkinter but not Python but am struggling to use the grid layout manager to arrange my controls as I want them.
Here is a (terrible) mockup of what I'm aiming for:
But my code (below) only renders this:
Here is my code:
'''
Configure main window controls
'''
postTtlFrame = Frame(tkRoot, bg="red")
postTtlLbl = Label(postTtlFrame, text="Page title:").grid(row=0, column=0)
postTtlEnt = Entry(postTtlFrame).grid(row=0, column=1)
postTtlFrame.grid(row=0, column=0)
postTxtFrame = Frame(tkRoot, bg="blue")
postTxtLbl = Label(postTxtFrame, text="Page body content:").grid(row=0, column=0)
postTxtArea = Text(postTxtFrame).grid(row=1, columnspan=1)
postTxtFrame.grid(row=1, column=0)
pageConfigFrame = Frame(tkRoot, bg="green")
headerDirecLbl = Label(tkRoot, text="Page header location:").grid(row=0, column=0)
headerDirecEnt = Entry(tkRoot).grid(row=0, column=1)
footerDirecLbl = Label(tkRoot, text="Page footer location:").grid(row=1, column=0)
footerDirecEnt = Entry(tkRoot).grid(row=1, column=1)
stylesDirecLbl = Label(tkRoot, text="Page stylesheet location:").grid(row=2, column=0)
stylesDirecEnt = Entry(tkRoot).grid(row=2, column=1)
outputDirecLbl = Label(tkRoot, text="Page output location:").grid(row=3, column=0)
outputDirecEnt = Entry(tkRoot).grid(row=3, column=1)
pageConfigFrame.grid(row=2, column=0)
buttonsFrame = Frame(tkRoot, bg="orange")
postBtn = Button(tkRoot, text="Post").grid(row=0, column=0)
exitBtn = Button(tkRoot, text="Exit", command=quitTk).grid(row=0, column=1)
buttonsFrame.grid(row=3, column=0)
Please can someone explain to me what on earth is going wrong!
Thanks in advance,
Ilmiont
Yeah, I have it working now #jeanrjc, my code was FULL of errors I realise now; here is what I used in the end:
'''
Configure main window controls
'''
postTtlFrame = Frame(tkRoot)
postTtlLbl = Label(postTtlFrame, text="Page title:").grid(row=0, column=0)
postTtlEnt = Entry(postTtlFrame).grid(row=0, column=1)
postTtlFrame.grid(row=0, column=0, sticky=W)
postTxtFrame = Frame(tkRoot)
postTxtLbl = Label(postTxtFrame, text="Page body content:").grid(row=0, column=0, sticky=W)
postTxtArea = Text(postTxtFrame).grid(row=1, columnspan=1)
postTxtFrame.grid(row=1, column=0, sticky=W)
pageConfigFrame = Frame(tkRoot)
headerDirecLbl = Label(pageConfigFrame, text="Page header location:").grid(row=0, column=0, sticky=W)
headerDirecEnt = Entry(pageConfigFrame).grid(row=0, column=1)
footerDirecLbl = Label(pageConfigFrame, text="Page footer location:").grid(row=1, column=0, sticky=W)
footerDirecEnt = Entry(pageConfigFrame).grid(row=1, column=1)
stylesDirecLbl = Label(pageConfigFrame, text="Page stylesheet location:").grid(row=2, column=0, sticky=W)
stylesDirecEnt = Entry(pageConfigFrame).grid(row=2, column=1)
outputDirecLbl = Label(pageConfigFrame, text="Page output location:").grid(row=3, column=0, sticky=W)
outputDirecEnt = Entry(pageConfigFrame).grid(row=3, column=1)
pageConfigFrame.grid(row=2, column=0, sticky=W)
buttonsFrame = Frame(tkRoot)
postBtn = Button(buttonsFrame, text="Post").grid(row=0, column=0)
exitBtn = Button(buttonsFrame, text="Exit", command=quitTk).grid(row=0, column=1)
buttonsFrame.grid(row=3, column=0, sticky=E)
Now I have the following result which is what I wanted:
Thanks anyway though!
First off, it's pointless to assign a widget to a variable if you're calling grid (or pack or place) at the same time. foo=Label(..).grid(...) will always return None because grid(...) always returns None. Also, I find that layout problems are much easier to solve when you separate your layout from widget creation.
So, let's start by doing that:
'''
Configure main window controls
'''
postTtlFrame = Frame(tkRoot, bg="red")
postTxtFrame = Frame(tkRoot, bg="blue")
pageConfigFrame = Frame(tkRoot, bg="green")
buttonsFrame = Frame(tkRoot, bg="orange")
postTtlFrame.grid(row=0, column=0)
postTxtFrame.grid(row=1, column=0)
pageConfigFrame.grid(row=2, column=0)
buttonsFrame.grid(row=3, column=0)
postTtlLbl = Label(postTtlFrame, text="Page title:")
postTtlEnt = Entry(postTtlFrame).grid(row=0, column=1)
postTtlLbl.grid(row=0, column=0)
postTxtLbl = Label(postTxtFrame, text="Page body content:")
postTxtArea = Text(postTxtFrame)
postTxtLbl.grid(row=0, column=0)
postTxtArea.grid(row=1, columnspan=1)
headerDirecLbl = Label(tkRoot, text="Page header location:")
headerDirecEnt = Entry(tkRoot)
footerDirecLbl = Label(tkRoot, text="Page footer location:")
footerDirecEnt = Entry(tkRoot)
stylesDirecLbl = Label(tkRoot, text="Page stylesheet location:")
stylesDirecEnt = Entry(tkRoot)
outputDirecLbl = Label(tkRoot, text="Page output location:")
outputDirecEnt = Entry(tkRoot)
postBtn = Button(tkRoot, text="Post")
exitBtn = Button(tkRoot, text="Exit")
headerDirecLbl.grid(row=0, column=0)
headerDirecEnt.grid(row=0, column=1)
footerDirecLbl.grid(row=1, column=0)
footerDirecEnt.grid(row=1, column=1)
stylesDirecLbl.grid(row=2, column=0)
stylesDirecEnt.grid(row=2, column=1)
outputDirecLbl.grid(row=3, column=0)
outputDirecEnt.grid(row=3, column=1)
postBtn.grid(row=0, column=0)
exitBtn.grid(row=0, column=1)
Now, I think you can see more clearly what is happening. The problems I see are:
You seem to want to organize things into four main areas, but your mock-up shows that everything in the first three areas should share the same grid structure, so I'm not sure why you're creating these frames
You don't assign any weights to rows or columns, so they won't grow and shrink how you expect them to
Most of the widgets all share a common parent of tkRoot rather than the organizational frames that you create, so the frames end up serving no purpose
Because many widgets share the same parent, you end up putting several widgets on top of each other in the same grid cell.
You don't use the sticky attribute, so widgets won't fill their columns.
The fix for all this depends on exactly what effect you're trying to achieve. If you want four independent areas you need to make sure each widget has the appropriate frame for its parent, rather than lumping most widgets in the tkRoot frame. This makes it likely that, for example, the postTtlEnt won't line up with the other entry widgets.
If you don't want four independent areas and do want the postTtlEnt widget to line up with everything else, get rid of the intermediate frames and put everything into a single grid.
Likely you want a mix -- the buttons don't necessarily need to share the same grid, but all of the entry widgets should share the same grid. Here's how I would do it. Notice that I only have one extra internal frame, for the buttons. Everything else shares a common parent. Also notice that I give a weight to one row and one column so that you get the right resize behavior:
Here's a complete, working example. It doesn't precisely match your mockup: the exit and post buttons don't have their own dedicated column, but if you really want that you can do that if you want. The space above the buttons seems wasted, so I elected to put the buttons directly below the input widgets.
'''
Configure main window controls
'''
postTtlLbl = Label(tkRoot, text="Page title:")
postTxtLbl = Label(tkRoot, text="Page body content:")
headerDirecLbl = Label(tkRoot, text="Page header location:")
footerDirecLbl = Label(tkRoot, text="Page footer location:")
stylesDirecLbl = Label(tkRoot, text="Page stylesheet location:")
outputDirecLbl = Label(tkRoot, text="Page output location:")
postTtlEnt = Entry(tkRoot)
postTxtArea = Text(tkRoot)
footerDirecEnt = Entry(tkRoot)
headerDirecEnt = Entry(tkRoot)
stylesDirecEnt = Entry(tkRoot)
outputDirecEnt = Entry(tkRoot)
buttonsFrame = Frame(tkRoot, bg="orange")
postBtn = Button(buttonsFrame, text="Post")
exitBtn = Button(buttonsFrame, text="Exit")
postBtn.pack(side="right")
exitBtn.pack(side="right")
postTtlLbl.grid(row=0, column=0, sticky="w")
postTxtLbl.grid(row=1, column=0, sticky="w")
headerDirecLbl.grid(row=3, column=0, sticky="w")
footerDirecLbl.grid(row=4, column=0, sticky="w")
stylesDirecLbl.grid(row=5, column=0, sticky="w")
outputDirecLbl.grid(row=6, column=0, sticky="w")
postTtlEnt.grid(row=0, column=1, sticky="ew")
postTxtArea.grid(row=2, column=0, columnspan=2, sticky="nsew")
headerDirecEnt.grid(row=3, column=1, sticky="ew")
footerDirecEnt.grid(row=4, column=1, sticky="ew")
stylesDirecEnt.grid(row=5, column=1, sticky="ew")
outputDirecEnt.grid(row=6, column=1, sticky="ew")
buttonsFrame.grid(row=7, column=0, sticky="ew", columnspan=2)
tkRoot.grid_rowconfigure(2, weight=1)
tkRoot.grid_columnconfigure(1, weight=1)
I manage to get something pretty close to what you want :
from Tkinter import *
root = Tk()
content = Label(root, padx=30,pady=30,background = "white")
content.grid(column=0, row=0, sticky=(N, S, E, W))
title_frame = Label(content, borderwidth=5, relief="sunken", padx=30,pady=30,background = "white")
title_frame.grid(column=0, row=0, sticky=(N))
body_frame = Label(content, borderwidth=5, relief="sunken", padx=30,pady=30,background = "white")
body_frame.grid(column=0, row=1, sticky=(N,W,E))
config_frame = Label(content, borderwidth=5, relief="sunken", padx=30,pady=30,background = "white")
config_frame.grid(column=0, row=2, sticky=(N, W))
button_frame = Label(content, borderwidth=5, relief="sunken", padx=30,pady=30,background = "orange")
button_frame.grid(column=1, row=2, sticky=(S, E))
title_entry = Entry(title_frame, background="lightblue")
title_entry.grid(column=1, row=0)
title_label = Label(title_frame,text = "Page title",background = "white")
title_label.grid(column=0,row=0)
body_text = Text(body_frame, background="lightblue")
body_text.grid(column=1,row=0)
body_label = Label(body_frame,text = "Page body content",background = "white")
body_label.grid(column=0, row=0)
header_entry = Entry(config_frame, background="lightblue")
header_entry.grid(column=1, row=0)
header_label = Label(config_frame,text = "header",background = "white")
header_label.grid(column=0,row=0)
footer_entry = Entry(config_frame, background="lightblue")
footer_entry.grid(column=1, row=1)
footer_label = Label(config_frame,text = "footer",background = "white")
footer_label.grid(column=0,row=1)
postBtn = Button(button_frame, text="Post")
postBtn.grid(row=0, column=0)
exitBtn = Button(button_frame, text="Exit")
exitBtn.grid(row=0, column=1)
And it displays that :
Concerning why your code doesn't work :
I guess it's because you defined your grid position with :
postTtlLbl = Label(postTtlFrame, text="Page title:").grid(row=0, column=0)
Instead of
postTtlLbl = Label(postTtlFrame, text="Page title:")
postTtlLbl.grid(row=0, column=0)
It's a problem when you expect to create an instance of your frame (by returning the instance into the postTtlLbl variable), because the grid method doesn't return anything so these variables handling the frame are Nonetype, and you can't do anything with them.
Hope it's clear.

Categories

Resources