Why I continue getting the error :
missing 1 required positional argument: 'category_id'
when the argument is already passed within query function in Backend class? I also don't understand the error of unfilled self or missing positional argument self:
missing 1 required positional argument: 'self'
I tried passing self to display_account_types() in Frontend class but it doesn't reflect. Do I need to pass self within the inner nested functions within a class?
import tkinter
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import sqlite3
root =Tk()
root.title('Simple Application')
root.config(bg='SlateGrey')
root.geometry("")
# BackEnd
class Backend():
def __init__(self):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.conn.execute("""CREATE TABLE IF NOT EXISTS account_type(
id INTEGER PRIMARY KEY,
category_type INTEGER NOT NULL,
category_id TEXT NOT NULL
)"""),
self.conn.commit()
self.conn.close()
def insert_account_type(self, category_type, category_id):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.cur.execute("""INSERT INTO account_type(category_id, category_type) VALUES(?,?);""",
(self,category_type, category_id,))
self.conn.commit()
self.conn.close()
def view_account_type(self):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.cur.execute("SELECT * FROM account_type")
self.rows = self.cur.fetchall()
self.conn.close()
return self.rows
# calling the class
tb = Backend()
# Front End
class Frontend():
def __init__(self, master):
# Frames
self.top_frame = LabelFrame(master,bg ='SlateGrey', relief=SUNKEN)
self.top_frame.pack()
self.bottom_frame = LabelFrame(master, bg = 'SlateGrey', relief=SUNKEN)
self.bottom_frame.pack()
self.right_frame = LabelFrame(self.top_frame, bg = 'SlateGrey', relief = FLAT,
text = 'Details Entry',fg = 'maroon')
self.right_frame.pack(side = RIGHT, anchor = NE)
self.side_frame = LabelFrame(self.top_frame,bg ='SlateGrey',relief=SUNKEN,text = 'Menu Buttons',fg = 'maroon')
self.side_frame.pack(side = LEFT,anchor = NW)
self.bot_frame = LabelFrame(self.bottom_frame, bg='Grey',relief = SUNKEN,text = 'Field View',fg = 'maroon')
self.bot_frame.pack(side = BOTTOM,anchor = SW)
# Side Buttons
self.btn1 = Button(self.side_frame,
text='Main Account Types',
bg='SteelBlue4',
font=('cambria', 11),
anchor=W,
fg='white',
width=18,height=2,
command=lambda :[self.main_account()])
self.btn1.grid(row=0, column=0, pady=0, sticky=W)
def main_account(self):
# variables
self.category_type = StringVar()
self.category_id = StringVar()
# functions
def add_main_accounts():
if self.category_type.get() == "" or self.category_id.get() == "":
tkinter.messagebox.showinfo('All fields are required')
else:
Backend.insert_account_type(
self.category_type.get(),
self.category_id.get(),) # category type unfilled
tkinter.messagebox.showinfo('Entry successful')
def display_account_types(self):
self.trv.delete(*self.trv.get_children())
for self.rows in Backend.view_account_type(self):
self.trv.insert("", END, values=self.rows)
def get_account_type(e):
self.selected_row = self.trv.focus()
self.data = self.trv.item(self.selected_row)
global row
row = self.data["values"]
"""Grab items and send them to entry fields"""
self.category_id.set(row[1])
self.category_type.set(row[2])
"""=================TreeView==============="""
# Scrollbars
ttk.Style().configure("Treeview", background = "SlateGrey", foreground = "white", fieldbackground = "grey")
scroll_x = Scrollbar(self.bot_frame, orient = HORIZONTAL)
scroll_x.pack(side = BOTTOM, fill = X)
scroll_y = Scrollbar(self.bot_frame, orient = VERTICAL)
scroll_y.pack(side = RIGHT, fill = Y)
# Treeview columns & setting scrollbars
self.trv = ttk.Treeview(self.bot_frame, height=3, columns=
('id', 'category_id', 'category_type'), xscrollcommand = scroll_x.set, yscrollcommand = scroll_y.set)
# Treeview style configuration
ttk.Style().configure("Treeview", background = "SlateGrey", foreground = "white", fieldbackground = "grey")
# Configure vertical and Horizontal scroll
scroll_x.config(command = self.trv.xview)
scroll_y.config(command = self.trv.yview)
# Treeview Headings/columns
self.trv.heading('id', text = "No.")
self.trv.heading('category_id', text = 'Category ID')
self.trv.heading('category_type', text = 'Category Type')
self.trv['show'] = 'headings'
# Treeview columns width
self.trv.column('id', width = 23)
self.trv.column('category_id', width = 70)
self.trv.column('category_type', width = 100)
self.trv.pack(fill = BOTH, expand = YES)
# Binding Treeview with data
self.trv.bind('<ButtonRelease-1>',get_account_type)
# Account Types Labels
self.lbl1 = Label(self.right_frame,text = 'Category ID',anchor = W,
width=10,font = ('cambria',11,),bg = 'SlateGrey')
self.lbl1.grid(row = 0,column = 0,pady = 5)
self.lbl2 = Label(self.right_frame, text = 'Category Type', anchor = W,
width = 10,font = ('cambria',11,),bg = 'SlateGrey')
self.lbl2.grid(row = 1, column = 0,pady = 5,padx=5)
self.blank_label = Label(self.right_frame, bg='SlateGrey')
self.blank_label.grid(row=2, columnspan=2, pady=10)
# Account Type Entries
self.entry1 = Entry(self.right_frame,textvariable = self.category_id,
font = ('cambria',11,),bg = 'Grey',width=14)
self.entry1.grid(row = 0,column=1,sticky = W,padx = 5)
self.entry2 = Entry(self.right_frame, textvariable = self.category_type,
font = ('cambria', 11,), bg = 'Grey',width = 14)
self.entry2.grid(row = 1, column = 1, sticky = W,pady = 5,padx = 5)
# Buttons
self.btn_1 = Button(self.right_frame,text = 'Add',font = ('cambria',12,'bold'),bg = 'SlateGrey',
activebackground='green', fg = 'white',width=12,height = 2,relief=RIDGE,
command = lambda :[add_main_accounts()])
self.btn_1.grid(row = 3,column = 0,pady = 15)
self.btn_2 = Button(self.right_frame, text = 'View', font = ('cambria', 12, 'bold'),
bg = 'SlateGrey',command=lambda :[display_account_types()],
activebackground='green', fg ='white', width=12, height = 2, relief = RIDGE)
self.btn_2.grid(row = 3, column = 1)
# calling the class
app = Frontend(root)
root.mainloop()
I got and answer to this question,
I just passed in the 'self' argument to the inner nested functions of the class as below and it worked.
# functions
def add_main_accounts(self):
if self.category_id.get() == "" or self.category_type.get() == "":
tkinter.messagebox.showinfo('All fields are required')
else:
Backend.insert_account_type(self,
self.category_id.get(),
self.category_type.get()) # category type unfilled
tkinter.messagebox.showinfo('Entry successful')
def display_account_types(self):
self.trv.delete(*self.trv.get_children())
for rows in Backend.view_account_type(self):
self.trv.insert("", END, values = rows)
return
def get_account_type(e):
self.selected_row = self.trv.focus()
self.data = self.trv.item(self.selected_row)
global row
self.row = self.data["values"]
"""Grab items and send them to entry fields"""
self.category_id.set(row[1])
self.category_type.set(row[2])
I think you should remove the self in display_account_types function like you did to the previous one.
Hi Can anyone know how to troubleshoot this.
url = "https://www.zillow.com/walnut-ca/?searchQueryState=%7B%22pagination%22%3A%7B%7D%2C%22usersSearchTerm%22%3A%22Walnut%2C%20CA%22%2C%22mapBounds%22%3A%7B%22west%22%3A-117.93482729053105%2C%22east%22%3A-117.75286623096073%2C%22south%22%3A33.93783156520187%2C%22north%22%3A34.06392018234896%7D%2C%22isMapVisible%22%3Atrue%2C%22mapZoom%22%3A12%2C%22filterState%22%3A%7B%22price%22%3A%7B%22min%22%3A400000%2C%22max%22%3A700000%7D%2C%22mp%22%3A%7B%22min%22%3A1448%2C%22max%22%3A2535%7D%2C%22sort%22%3A%7B%22value%22%3A%22globalrelevanceex%22%7D%7D%2C%22isListVisible%22%3Atrue%7D"
d = {'key':'value'}
print(d)
d['new key'] = 'new value'
print(d)
query_houses = {}
house_no = 0
while True:
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
houses = soup.find_all('article',{'class':'list-card list-card-short list-card_not-saved'})
for house in houses:
location = house.find('address',{'class': 'list-card-addr'})
value = house.find('div',{'class': 'list-card-price'})
detail = house.find('ul', {'class':'list-card-details'})
seller = house.find('div',{'class':'list-card-truncate'})
link = house.find('a', {'class': 'list-card-link'}).get('href')
house_response = requests.get(link)
house_data = house_response.text
house_soup = BeautifulSoup(house_data, 'html.parser')
square = house_soup.find('span',{'class':'ds-bed-bath-living-area'})
year_build = house_soup.find('span',{'class':'ds-body ds-home-fact-value'})
estimated_sales_range = house_soup.find('div',{'class':'Spacer-sc-17suqs2-0 pfWXf'})
house_no+=1
query_houses[house_no] = [location, value, detail, seller, link, square, year_build, estimated_sales_range]
url_tag = soup.find('a',{'title':'Next-page'})
if url_tag.get('href'):
url= 'https://zillow.com' + url_tag.get('href')
print(url)
else:
break
Using the following code, I'm trying to create a document in which pages 2 and 3 are landscape while the others are portrait. All should be 8.5" x 11".
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (DocX document = DocX.Create(ms))
{
document.PageLayout.Orientation = Novacode.Orientation.Portrait;
document.PageWidth = 816F;
document.PageHeight = 1056F;
document.MarginTop = 50F;
document.MarginRight = 50F;
document.MarginBottom = 75F;
document.MarginLeft = 50F;
document.AddHeaders();
document.AddFooters();
document.DifferentFirstPage = true;
document.DifferentOddAndEvenPages = false;
Header header_first = document.Headers.first;
Header header_main = document.Headers.odd;
Footer footer_main = document.Footers.odd;
Novacode.Table tHeaderFirst = header_first.InsertTable(2, 1);
tHeaderFirst.Design = TableDesign.None;
tHeaderFirst.AutoFit = AutoFit.Window;
Paragraph pHeaderFirst = header_first.Tables[0].Rows[0].Cells[0].Paragraphs[0];
Novacode.Image imgHeaderFirst = document.AddImage(ctx.Server.MapPath("~/proposal-assets/header-front.jpg"));
pHeaderFirst.InsertPicture(imgHeaderFirst.CreatePicture());
Novacode.Table tHeaderMain = header_main.InsertTable(2, 1);
tHeaderMain.Design = TableDesign.None;
tHeaderMain.AutoFit = AutoFit.Window;
Paragraph pHeader = header_main.Tables[0].Rows[0].Cells[0].Paragraphs[0];
Novacode.Image imgHeader = document.AddImage(ctx.Server.MapPath("~/proposal-assets/header-internal-portrait.jpg"));
pHeader.InsertPicture(imgHeader.CreatePicture());
Paragraph pFooter = footer_main.Paragraphs.First();
pFooter.Alignment = Alignment.center;
pFooter.Append("Page ");
pFooter.AppendPageNumber(PageNumberFormat.normal);
pFooter.Append("/");
pFooter.AppendPageCount(PageNumberFormat.normal);
Paragraph p1 = document.InsertParagraph("test");
p1.InsertPageBreakAfterSelf();
document.InsertSection(true);
document.PageLayout.Orientation = Novacode.Orientation.Landscape;
//document.PageWidth = 1056F;
//document.PageHeight = 816F;
Paragraph p2 = document.InsertParagraph("test");
p2.InsertPageBreakAfterSelf();
Paragraph p3 = document.InsertParagraph("test");
p3.InsertPageBreakAfterSelf();
document.InsertSection(true);
document.PageLayout.Orientation = Novacode.Orientation.Portrait;
//document.PageWidth = 816F;
//document.PageHeight = 1056F;
Paragraph p4 = document.InsertParagraph("test");
p4.InsertPageBreakAfterSelf();
Paragraph p5 = document.InsertParagraph("test");
p5.InsertPageBreakAfterSelf();
Paragraph p6 = document.InsertParagraph("test");
p6.InsertPageBreakAfterSelf();
document.Save();
}
}
I'm having several issues with this.
First, if I set the orientation once at the beginning, all the pages come out the correct size, but once I add the 2nd and 3rd changes to PageLayout.Orientation, suddenly ALL my pages are the wrong size.
Second, inserting the sections does weird things with my headers and footers. The first page of the 3rd section acts like it's the first page of the document and takes the first page header and footer.
Finally, adding the 2nd and 3rd changes to PageLayout.Orientation doesn't actually change the page orientations. As you can see in the commented out code, I've also tried setting new page heights and widths after changing the layout. Doing so makes my pages go back to the correct size, but in no way affects the orientation.
What am I missing? Any help would be greatly appreciated.
Finally! I've worked out a usable solution which I'll place here in hopes it'll help someone else.
document.PageLayout.Orientation = Novacode.Orientation.Portrait;
document.PageWidth = 816F;
document.PageHeight = 1056F;
document.MarginTop = 50F;
document.MarginRight = 50F;
document.MarginBottom = 75F;
document.MarginLeft = 50F;
document.AddHeaders();
document.AddFooters();
document.DifferentFirstPage = true;
document.DifferentOddAndEvenPages = false;
Header header_first = document.Headers.first;
Header header_main = document.Headers.odd;
Footer footer_main = document.Footers.odd;
Paragraph pHeaderFirst = header_first.Paragraphs.First();
Novacode.Image imgHeaderFirst = document.AddImage(ctx.Server.MapPath("~/proposal-assets/header-front.jpg"));
pHeaderFirst.Alignment = Alignment.center;
pHeaderFirst.SpacingAfter(25);
pHeaderFirst.AppendPicture(imgHeaderFirst.CreatePicture());
Paragraph pHeader = header_main.Paragraphs.First();
Novacode.Image imgHeader = document.AddImage(ctx.Server.MapPath("~/proposal-assets/header-internal-portrait.jpg"));
pHeader.Alignment = Alignment.center;
pHeader.SpacingAfter(25);
pHeader.AppendPicture(imgHeader.CreatePicture());
Paragraph pFooter = footer_main.Paragraphs.First();
pFooter.Alignment = Alignment.center;
pFooter.Append("Page ");
pFooter.AppendPageNumber(PageNumberFormat.normal);
pFooter.Append("/");
pFooter.AppendPageCount(PageNumberFormat.normal);
Paragraph p1 = document.InsertParagraph("test");
System.IO.MemoryStream ms2 = new System.IO.MemoryStream();
DocX document2 = DocX.Create(ms2);
document2.PageLayout.Orientation = Novacode.Orientation.Landscape;
document2.PageWidth = 1056F;
document2.PageHeight = 816F;
document2.MarginTop = 50F;
document2.MarginRight = 50F;
document2.MarginBottom = 75F;
document2.MarginLeft = 50F;
Paragraph p2 = document2.InsertParagraph("test --- doc 2");
p2.InsertPageBreakAfterSelf();
Paragraph p3 = document2.InsertParagraph("test --- doc 2");
document2.Save();
document.InsertSection();
document.InsertDocument(document2);
System.IO.MemoryStream ms3 = new System.IO.MemoryStream();
DocX document3 = DocX.Create(ms3);
document3.PageLayout.Orientation = Novacode.Orientation.Portrait;
document3.PageWidth = 816F;
document3.PageHeight = 1056F;
document3.MarginTop = 50F;
document3.MarginRight = 50F;
document3.MarginBottom = 75F;
document3.MarginLeft = 50F;
Paragraph p4 = document3.InsertParagraph("test");
p4.InsertPageBreakAfterSelf();
Paragraph p5 = document3.InsertParagraph("test");
p5.InsertPageBreakAfterSelf();
Paragraph p6 = document3.InsertParagraph("test");
document3.Save();
document.InsertSection();
document.InsertDocument(document3);
document.Save();
Creating the different sections as separate documents and inserting them into the main document worked well and solved all my problems.
I want to set the color of a toggle button of my choice in the panel that I have created. The problem is that in the numerous toggle buttons that I have displayed on my panel when I want to change the color of each one only the color of the last button changes. Here's my code:
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None)
self.panel = wx.Panel(self,wx.ID_ANY)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.flags_panel = wx.Panel(self, wx.ID_ANY, style = wx.SUNKEN_BORDER)
self.sizer.Add(self.flags_panel)
self.SetSizer(self.sizer,wx.EXPAND | wx.ALL)
self.flags = Flags(self.flags_panel, [8,12])
self.flags.Show()
class Flags (wx.Panel):
def __init__(self,panel, num_flags = []):#,rows = 0,columns = 0,radius = 0, hspace = 0, vspace = 0,x_start = 0, y_start = 0
wx.Panel.__init__(self,panel,-1, size = (350,700))
num_rows = num_flags[0]
num_columns = num_flags[1]
x_pos_start = 10
y_pos_start = 10
i = x_pos_start
j = y_pos_start
buttons = []
for i in range (num_columns):
buttons.append('toggle button')
self.ButtonValue = False
for button in buttons:
index = 0
while index != 15:
self.Button = wx.ToggleButton(self,-1,size = (10,10), pos = (i,j))
self.Bind(wx.EVT_TOGGLEBUTTON,self.OnFlagCreation, self.Button)
self.Button.Show()
i += 15
index += 1
j += 15
i = 10
self.Show()
def OnFlagCreation(self,event):
if not self.ButtonValue:
self.Button.SetBackgroundColour('#fe1919')
self.ButtonValue = True
else:
self.Button.SetBackgroundColour('#14e807')
self.ButtonValue = False
if __name__ == '__main__':
app = wx.App(False)
frame = Frame()
frame.Show()
app.MainLoop()
Your problem is quite simple. The last button is always changed because it's the last button defined:
self.Button = wx.ToggleButton(self,-1,size = (10,10), pos = (i,j))
Each time through the for loop, you reassign the self.Button attribute to a different button. What you want to do is extract the button from your event object and change its background color. So change your function to look like this:
def OnFlagCreation(self,event):
btn = event.GetEventObject()
if not self.ButtonValue:
btn.SetBackgroundColour('#fe1919')
self.ButtonValue = True
else:
btn.SetBackgroundColour('#14e807')
self.ButtonValue = False
See also:
http://www.blog.pythonlibrary.org/2011/09/20/wxpython-binding-multiple-widgets-to-the-same-handler/
So i've created 5 different arrays for labels These are
Dim ovsoLabels As Label(), customerLabels() As Label, itemNameLabels() As Label, quantityLabels() As Label, topRightItemNameLbls(5) As Label
Dim indexLabels() As Label
After that I have a function that assigns those variables to actual labels.
'assign labels to array
ovsoLabels(0) = oVSO10
ovsoLabels(1) = oVSO11
ovsoLabels(2) = oVSO12
ovsoLabels(3) = oVSO13
ovsoLabels(4) = oVSO14
customerLabels(0) = custLbl20
customerLabels(1) = custLbl21
customerLabels(2) = custLbl22
customerLabels(3) = custLbl23
customerLabels(4) = custLbl24
itemNameLabels(0) = nameLbl1
itemNameLabels(1) = nameLbl2
itemNameLabels(2) = nameLbl3
itemNameLabels(3) = nameLbl4
itemNameLabels(4) = nameLbl5
quantityLabels(0) = quantLbl1
quantityLabels(1) = quantLbl2
quantityLabels(2) = quantLbl3
quantityLabels(3) = quantLbl4
quantityLabels(4) = quantLbl6
indexLabels(0) = indexLbl10
indexLabels(1) = indexLbl11
indexLabels(2) = indexLbl12
indexLabels(3) = indexLbl13
indexLabels(4) = indexLbl14
After that I call the function in my timer tick
and this is what i'm triying to do (Not quoteArray has numbers in it 0 - infinity)
For i = 0 To 4
If quantityArray(i) = Nothing Then
ElseIf quantityArray(i) = 0 Then
quantityLabels(i).ForeColor = Drawing.Color.Green
customerLabels(i).ForeColor = Drawing.Color.Green
itemNameLabels(i).ForeColor = Drawing.Color.Green
ovsoLabels(i).ForeColor = Drawing.Color.Green
indexLabels(i).ForeColor = Drawing.Color.Green
Else
quantityLabels(i).ForeColor = Drawing.Color.Black
customerLabels(i).ForeColor = Drawing.Color.Black
itemNameLabels(i).ForeColor = Drawing.Color.Black
ovsoLabels(i).ForeColor = Drawing.Color.Black
indexLabels(i).ForeColor = Drawing.Color.Black
End If
Next
This is my first post, so tell me if I can format better. The error I'm getting is that it tells me that there is no object and I need to use the keyword new. Not sure what that means, thanks!