I created a .csv which shows below, and when I try to use the label it told me"'DataFrame' object has no attribute 'label'",the code is as follows
why my columns "cd,cs,cf" is not labels?enter image description here
I wish I input "aiya.label" it could turns out cd,cs,cf
I am using PyQt based on Qt4. My Editor is PyCharm 2017.3 and my python version is 3.4. I am scraping some text from a website. I am trying to align that text to the center of the cell in a QTableWidget.
item = QTableWidgetItem(scraped_age).setTextAlignment(Qt.AlignHCenter)
self.tableWidget.setItem(x, 2,item)
Therefore while putting the item in the cell, I am trying to align it as per the documentation. The problem is that the data is not showing up.
It did show up when I removed setTextAlignment method as shown below
item = QTableWidgetItem(scraped_age)
self.tableWidget.setItem(x, 2,item)
This line of code:
item = QTableWidgetItem(scraped_age).setTextAlignment(Qt.AlignHCenter)
will not work properly, because it throws away the item it creates before assigning it to the variable. The variable will in fact be set to None, which is the return value of setTextAlignment(). Instead, you must do this:
item = QTableWidgetItem(scraped_age) # create the item
item.setTextAlignment(Qt.AlignHCenter) # change the alignment
This didn't work for me, and I'm not sure if it is because I'm using PyQt5 or it i did something wrong. I was trying to find something similar but for the whole table, and i finally stumbled upon something that worked and lets you center every cells or just one column at a time.
You have to use the delegate method:
#You're probably importing QtWidgets to work with the table
#but you'll also need QtCore for the delegate class
from PyQt5 import QtCore, QtWidgets
class AlignDelegate(QtWidgets.QStyledItemDelegate):
def initStyleOption(self, option, index):
super(AlignDelegate, self).initStyleOption(option, index)
option.displayAlignment = QtCore.Qt.AlignCenter
After implementing this in your code, you can add the following to your main window class or wherever the table is defined:
delegate = AlignDelegate(self.tableWidget)
self.tableWidget.setItemDelegateForColumn(2, delegate) #You can repeat this line or
#use a simple iteration / loop
#to align multiple columns
#If you want to do it for all columns:
#self.tableWidget.setItemDelegate(delegate)
Know this is an old question, but hope it can help someone else.
Bit late to the party but for those of you wondering how to do this on pyqt5
table = QTableWidgetItem() #QTWidgets.QTableWidgetItem() if importing QWidget from PyQt5
table.setTextAlignment(number)
setTextAlignment takes an int for the argument (alignment). Put the number in to get the result:
0:left
1:left
2:right
3:right
4:centre
I am facing problem with getting exact Coordinate of text, So can I can get whole code for this problem(Including myLocationExtractionStratey class as well).
I'm trying to build a bot with python. I want python to act as an autofill and I made this part of programm :
> ord_billing_name=driver.find_element_by_xpath('//*[#id="cart-
address"]/fieldset/div[1]').click()
> ord_billing_name.send_keys(buyerName)
(The programm to get to the website works)
But python displays :
AttributeError: 'NoneType' object has no attribute 'send_keys'
And the case is not filled on the website.
Please, can someone tell me what is wrong ?
Thanks a bunch.
.click() doesn't return anything but you are assigning the return to ord_billing_name. You need to separate this into 3 lines... first line is grabbing the element and assigning it to the variable. The other two lines are click() and send_keys().
ord_billing_name = driver.find_element_by_xpath('//*[#id="cart-address"]/fieldset/div[1]')
ord_billing_name.click()
ord_billing_name.send_keys(buyerName)
I am trying to show print button in jquery data table. But getting error like "Cannot read property 'ext' of undefined.
Script which I used are,
script_tag('www/js/data-tables/buttons.html5.js').
script_tag('www/js/data-tables/buttons.print.js').
script_tag('www/js/data-tables/dataTables.buttons.js').
script_tag('www/js/data-tables/jquery.dataTables.js')
And css ,
link_tag('www/js/data-tables/buttons.dataTables.css')
Declare the scripts in the reverse order :
script_tag('www/js/data-tables/jquery.dataTables.js')
script_tag('www/js/data-tables/dataTables.buttons.js').
script_tag('www/js/data-tables/buttons.html5.js').
script_tag('www/js/data-tables/buttons.print.js').
dataTables extensions wants to access $.fn.DataTable.ext, which not is present if jquery.dataTables.js not yet is included.