My function:
def buttons_for_country(main_master,datasets):
country_list = every_country_in_datasets(datasets)
rows = 0
columns = 0
for i in range(1,len(country_list)):
name = "button",i
name = tkinter.Button(master = main_master,
command = lambda: plot(10000)
height = 2,
width=10,
text=country_list[i-1])
if rows == 12:
rows = 0
colums += 1
name.grid(rows,columns)
rows += 1
name.pack()
It cames error at name.grid(rows,columns) said:
Traceback (most recent call last):
File "c:/Python/Covid/Cov_predict.py", line 93, in <module>
buttons_for_country(window,df)
File "c:/Python/Covid/Cov_predict.py", line 75, in buttons_for_country
name.grid(rows,columns)
TypeError: grid_configure() takes from 1 to 2 positional arguments but 3 were given
It seems fine with by giving 2 params rows and columns
But it said i given 3 paramsWhere do i did wrong here?
You should specify the row and column as keyword arguments.
name.grid(row=rows, column=columns)
You also need to remove name.pack() - a widget can only be controlled by a single geometry manager, and the last one you use is the one that is in control. Calling pack() after calling grid() removes all of the benefits of calling grid().
Related
I want to accept different data types from user using list comprehension in python 3
This is my code with for loop -
stuRecords = []
for i in range(1, num+1):
print('Enter the name and marks of {} student.'.format(i))
name = input()
marks = int(input())
stuRecords.append([name,marks])
How can I write this code using list comprehension. I have tried this -
stuRecords = [[name,marks] for name,marks in input(f'\nEnter the name and
marks of {num} students').strip().split()][:num]
But I get this error -
Enter the name and marks of 2 students...John
Traceback (most recent call last):
File "HR_NestedList.py", line 13, in <module>
stuRecords = [[name,marks] for name,marks in input(f'\nEnter the name and marks of {num} students...').strip().split()][:num]
File "HR_NestedList.py", line 13, in <listcomp>
stuRecords = [[name,marks] for name,marks in input(f'\nEnter the name and marks of {num} students...').strip().split()][:num]
ValueError: too many values to unpack (expected 2)
Try this :
num = 3
stuRecords = [[[name, int(marks)] for name, marks in
[input(f'Enter the name and marks of {i}th students:\n').strip().split()]][0]
for i in range(1, num+1)]
print(stuRecords)
am trying to assert the row text in webtable but am facing issue,getting some attribute error.help me in this
webtable=driver.find_element_by_class_name("dojoxGridScrollbox")
for row in webtable.find_elements_by_xpath("//*[#id='dojox_grid__TreeView_1']/div/div/div/div[1]/table/tbody/tr"):
print(row.text)
driver.implicitly_wait(5)
#assert webtable.row.text== name
assert driver.row.find(name)
Traceback (most recent call last):
File "C:\Users\rajesn\eclipse\Pyhton\GUI_Automation\GuiAutomationTest.py", line 11, in
obj.peer_node()
File "C:\Users\rajesn\eclipse\Pyhton\GUI_Automation\gui_Module.py", line 83, in peer_node
assert driver.row.find(name)
AttributeError: 'WebDriver' object has no attribute 'row'
Given that xpath is very expressive and can be for specific for selecting nodes in a tree, a loop isn't necessary for getting at the inserted table row.
If table row is inserted in top, you can write the query as
first_tr_xpath = "(//*[#id='dojox_grid__TreeView_1']/div/div/div/div[1]/table/tbody/tr)[1]"
first_tr, = webtable.find_elements_by_xpath(first_tr_xpath)
assert first_tr.text.find(name) != -1
If table row is inserted on end of table, it's more like
last_tr_xpath = "(//*[#id='dojox_grid__TreeView_1']/div/div/div/div[1]/table/tbody/tr)[last()]"
last_tr, = webtable.find_elements_by_xpath(last_tr_xpath)
assert last_tr.text.find(name) != -1
I am trying to get value which is selected from the list in drop-down menu but having this error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Python36\lib\tkinter\__init__.py", line 3436, in __call__
self.__callback(self.__value, *args)
TypeError: changeInLymph() takes 0 positional arguments but 1 was given
My code is:
# dropDown options
def changeInLymph():
data = "you selected the option " + var10.get()
label10.config(text=data)
var10 = StringVar()
choices = ['bean', 'oval', 'round']
# set the default option
popupMenu = OptionMenu(f1, var10, *choices ).grid(row = 20, column =5)
Label(f1, text="Choose a dish").grid(row = 19, column = 5)
label10 = Label(f1).grid(row=21,column=1)
where i am doing wrong please help anybody.
I want to perform column subtraction. for example [[0,2],[2,5],[3,11]] for this I want to perform (5-2),(11-5). then find which has the maximum difference.so for that I created a dictionary and store the differences along with its pair. for example difference of (5-2) is stored with 0, and difference of (11-5) is stored with 2.
error is :
Traceback (most recent call last): File
"/home/viki/Music/keypress.py", line 14, in
keypressTime(l) File "/home/viki/Music/keypress.py", line 10, in keypressTime
d = x[i+1][1] - x[i][1] IndexError: list index out of range
import operator
l = [[0,2],[2.4],[0,8],[3,9],[5,20]]
def keypressTime(x):
dic = {}
d = 0
for i in range(len(x)-1):
if i <(len(x)-1):
d = x[i+1][1] - x[i][1]
dic["i"] = d
return max(dict.items(),key=operator.itemgetter(1))[0]
keypressTime(l)
There is a typo in the variable declaration of l.
l = [[0,2],[2.4],[0,8],[3,9],[5,20]] -> change 2.4 to 2,4
And dict.items() should probably be dic.items()
#app.route('/')
def index():
tpopDloads = popDloads
tpopShipped = popShipped
locPopDload = []
locPopShipped = []
popDinfo = []
popSinfo = []
popDloadsOrd = sorted(tpopDloads, reverse=True)
popShippedOrd = sorted(tpopShipped, reverse=True)
for i in range(3):
locPopDload.append(tpopDloads.index(popDloadsOrd[i]))
popDinfo.append(dProducts[locPopDload[i]])
tpopDloads[tpopDloads.index(popDloadsOrd[i])] = -1 #Problem line#
for i in range(3):
locPopShipped.append(tpopShipped.index(popShippedOrd[i]))
popSinfo.append(sProducts[locPopShipped[i]])
tpopShipped[tpopShipped.index(popDloadsOrd[i])] = -1
return render_template('index.html', popDinfo=popDinfo, popSinfo=popSinfo)
The error I'm getting is:
File "/var/lib/openshift/5697165a0c1e66eb870000fb/app-root/runtime /repo/flaskapp.py", line 47, in index
tpopShipped[tpopShipped.index(popDloadsOrd[i])] = -1
ValueError: 0 is not in list
This is using two variable that are popDloads and popShipped which are both lists that contain a set of integers. I don't see why it's not working as it is trying to find the actual index of a number after the list has been ordered. It also works when the numbers are all zero, it's only after I change the numbers in another piece of code that I run into problems.
The error is telling you why your code isn't working. 0 isn't in the list tpopShipped.
>>> [1,2,3].index(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 0 is not in list