Why do I get error "missing 1 required positional argument"? - sqlite

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.

Related

How to get_lines from point to point in manim?

When I try to get_horizontal_line from one dot to another it goes from the y-axes. I want that the dashedline comes from the point [1;1] to point [3;1]. Because now it comes from [0;1] to[3;1]directly from the axis coordinate.
I don't know how to get lines not from the axis but from the point. Also here is my code:
from manim import *
class KvadratickaFunkcia(Scene):
def construct(self):
suradnicovaOs = Axes(
x_range=[-8,8,1],
y_range=[-8,8,1],
tips=False,
x_length=10,
y_length=10,
axis_config=
{
"stroke_color": GREY_A,
"include_numbers": True,
}
)
#vzorec x-2
posunParabolyVzorecMinus2a = MathTex("{y = (x-2)^2+0}", font_size=50).to_edge(UL).set_color(YELLOW)
posunParabolyVzorecMinus2a[0][5].set_color(RED)
posunParabolyVzorecMinus2a[0][9].set_color(RED)
#vzorec parabola y: (y-2)**2+0
parabolaMinus2a = suradnicovaOs.plot(lambda y: (y-2)**2+0 )
#body 1,2,3
bodMinus2a= Dot(suradnicovaOs.coords_to_point(1, 1), color=YELLOW)
bodkociarkaMinus2a = suradnicovaOs.get_horizontal_line(suradnicovaOs.c2p(3,1))
bodMinus2a2 = Dot(suradnicovaOs.coords_to_point(2, 0), color=YELLOW)
bodkociarkaMinus2a2 = suradnicovaOs.get_vertical_line(suradnicovaOs.c2p(1,1))
bodMinus2a3 = Dot(suradnicovaOs.coords_to_point(3, 1), color=YELLOW)
bodkociarkaMinus2a3 = suradnicovaOs.get_vertical_line(suradnicovaOs.c2p(3,1))
VsetkyBodyMinus123AA = VGroup(bodMinus2a,bodMinus2a2,bodMinus2a3,bodkociarkaMinus2a,bodkociarkaMinus2a2,bodkociarkaMinus2a3)
self.play(Write(suradnicovaOs), run_time=3)
self.play(Create(posunParabolyVzorecMinus2a))
self.play(Create(VsetkyBodyMinus123AA))
self.wait()
self.play(FadeIn(parabolaMinus2a))
image of my problem:
Welcome to the SO! You can use the .get_center() functions of the two points and connect them via DashedLine with stroke_width of 2. You should ignore bodkociarkaMinus2a and use the following line:
my_line: DashedLine = DashedLine(
bodMinus2a.get_center(), bodMinus2a3.get_center(),stroke_width = 2
)
Here is the full code:
from manim import *
class KvadratickaFunkcia(Scene):
def construct(self):
suradnicovaOs = Axes(
x_range=[-8,8,1],
y_range=[-8,8,1],
tips=False,
x_length=10,
y_length=10,
axis_config=
{
"stroke_color": GREY_A,
"include_numbers": True,
}
)
#vzorec x-2
posunParabolyVzorecMinus2a = MathTex("{y = (x-2)^2+0}", font_size=50).to_edge(UL).set_color(YELLOW)
posunParabolyVzorecMinus2a[0][5].set_color(RED)
posunParabolyVzorecMinus2a[0][9].set_color(RED)
#vzorec parabola y: (y-2)**2+0
parabolaMinus2a = suradnicovaOs.plot(lambda y: (y-2)**2+0 )
#body 1,2,3
bodMinus2a= Dot(suradnicovaOs.coords_to_point(1, 1), color=YELLOW)
#bodkociarkaMinus2a = suradnicovaOs.get_horizontal_line(suradnicovaOs.c2p(3,1))
bodMinus2a2 = Dot(suradnicovaOs.coords_to_point(2, 0), color=YELLOW)
bodkociarkaMinus2a2 = suradnicovaOs.get_vertical_line(suradnicovaOs.c2p(1,1))
bodMinus2a3 = Dot(suradnicovaOs.coords_to_point(3, 1), color=YELLOW)
bodkociarkaMinus2a3 = suradnicovaOs.get_vertical_line(suradnicovaOs.c2p(3,1))
my_line: DashedLine = DashedLine(
bodMinus2a.get_center(), bodMinus2a3.get_center(),stroke_width = 2
)
VsetkyBodyMinus123AA = VGroup(bodMinus2a,bodMinus2a2,bodMinus2a3, my_line, bodkociarkaMinus2a2, bodkociarkaMinus2a3)
self.play(Write(suradnicovaOs), run_time=3)
self.play(Create(posunParabolyVzorecMinus2a))
self.play(Create(VsetkyBodyMinus123AA))
self.wait()
self.play(FadeIn(parabolaMinus2a))

web scraper Python AttributeError: 'NoneType' object has no attribute 'get'

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

Only one button in a panel with multiple togglebuttons changes color - wxPython

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/

Putting labels inside of a vb.net Array

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!

Tkinter Module refresh window

My program is for a hangman game and I can't get the window to refresh once the button is clicked. At least i think that is the problem Here is my code for the window and the function linked to the button, let me know if you need more code:
def game(self, num):
self.game_window = tkinter.Tk()
self.game_window.title('Hangman')
self.game_window.geometry('200x150')
self.f1 = tkinter.Frame(self.game_window)
self.f2 = tkinter.Frame(self.game_window)
self.f3 = tkinter.Frame(self.game_window)
self.f4 = tkinter.Frame(self.game_window)
self.f5 = tkinter.Frame(self.game_window)
self.f6 = tkinter.Frame(self.game_window)
self.f7 = tkinter.Frame(self.game_window)
self.f8 = tkinter.Frame(self.game_window)
self.f9 = tkinter.Frame(self.game_window)
self.num = num
word_list = ['PYTHON','SOMETHING','COMPLETELY','DIFFERENT',
'LIST','STRING','SYNTAX','OBJECT','ERROR',
'EXCEPTION','OBJECT','CLASS','PERFORMANCE','VISUAL',
'JAVASCRIPT','JAVA','PROGRAMMING','TUPLE','ASSIGN',
'FUNCTION','OPERATOR','OPERANDS','PRECEDENCE',
'LOOPS','SENTENCE','TABLE','NUMBERS','DICTIONARY',
'GAME','SOFTWARE','NETWORK','SOCIAL','EDUCATION',
'MONITOR','COMPUTER']
shuffle = random.shuffle(word_list)
rand = random.choice(word_list)
self.word = rand.lower()
self.current = len(self.word)*'*'
self.letters = []
#self.start_lives = tkinter.Label(self.f1, text = 'You\'ve started the '
#'game with %s lives.\n'%(self.num))
#self.start_lives.pack(side = 'left')
self.lives_rem = tkinter.Label(self.f2,
text = 'Lives remaining: '+str(self.lives_left()))
self.lives_rem.pack(side = 'left')
self.guess_letter = tkinter.Label(self.f3, text = 'Guess a letter: ')
self.guess_entry = tkinter.Entry(self.f3, width = 10)
self.guess_letter.pack(side = 'left')
self.guess_entry.pack(side = 'left')
#self.f1.pack()
self.f2.pack()
self.f3.pack()
self.guess_button = tkinter.Button(self.f6,
text = 'Guess!',
command = self.update(self.guess_entry.get()))
self.guess_button.pack(side = 'left')
self.quit_game = tkinter.Button(self.f6,
text = 'Quit Game',
command = self.game_window.destroy)
self.quit_game.pack(side = 'left')
self.f6.pack()
def update(self, letter):
if letter in self.word and letter not in self.letters:
pos = self.word.index(letter)
self.current1 = list(self.current)
self.current1[pos] = letter.upper()
self.current2 = ''.join(self.current1)
self.letters.append(letter)
elif letter in self.letters:
self.already_guessed = tkinter.messagebox.showinfo('Error!',
'This letter has already '
'been guessed')
#letter is not in the word
elif letter not in self.word:
self.sorry = tkinter.Label(self.f5,
text = 'Sorry, guess again!')
self.sorry.pack(side = 'left')
self.letters.append(letter)
self.num -= 1
self.incorrect_word = tkinter.Label(self.f4,
text = 'Word: '+self.current)
self.incorrect_word.pack(side='left')
self.f5.pack()
self.f4.pack()
return self.current
These are two methods in a Hangman class.
The line that defines the guess button:
self.guess_button = tkinter.Button(self.f6, text = 'Guess!', command = self.update(self.guess_entry.get()))
requires modification. the command argument for the Button class should be a function, but this line is calling that function (which sends the output of the function as the value for the command argument). As you may see on the quit_game button definition, the self.game_window.destroy function is provided as the command, but is not called right now.
I suggest changing this line like this:
self.guess_button = tkinter.Button(self.f6, text = 'Guess!', command = self._on_guess_button_click)
and then add a new method to your class like this:
def _on_guess_button_click (self):
self.update(self.guess_entry.get())

Resources