I have got 2 situation when trying to call QStatusBar.showMessage().
- 1st: Got error: TypeError: 'QStatusBar' object is not callable
- 2nd: It does not effect and nothing happen. I got a blank status bar, without any error message.
Here the detail:
The MainWindow class:
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
This module has been imported to the main file. Then, in the main file, I have called QtGui.QStatusBar's showMessage() method, and got two following issues.
1. TypeError: 'QStatusBar' object is not callable
I have used following code statement to call QtGui.QStatusBar's showMessage() method:
self.ui.statusbar().showMessage("You have selected: %s" % self.filename, msecs= 5)
2. A blank statusbar; no effect and there's any error message.
I have used this code statement:
self.ui.statusbar.showMessage("You have selected: %s" % self.filename, msecs= 5)
I haven't got any error, but it's also take no effect.
Someone can help me to figure out that what I have wrong and how to fix it? Thank you!
You use msecs= 5.
This means "show the message for 5 milliseconds"!
Please try with msecs=5000.
You need to remove the '()' behind 'statusbar' because it is isn't a method.
Related
I've snipped out parts of the code, as i suspect the answer is quite newbie :)
I am trying to validate the input in the Entry by clicking the button (which references to a validation funciton). However the path_directory-variable are not updated (it keeps the initial value).
How do I update it when the button is clicked?
directory = tk.Entry(entry_frame)
validate_button= tk.Button(paths_frame, text='Next', command=lambda path_directory=directory.get(): self.validate_path(path_directory))
def validate_path(self, path_directory):
if path.exists(path_directory):
print('# Path validation succuessful: ', path_directory)
else:
print('# Path validation failed: ', path_directory)
The problem is that you are getting the value only on lambda init. Simply use a function, not lambda, like this:
def validate_click():
path_directory=directory.get()
self.validate_path(path_directory)
validate_button= tk.Button(paths_frame, text='Next', command=validate_click)
Hope that's helpful!
I am trying to replicate the example shown in this SO question, and I am stumbling in what looks like a Twython bug, appreciate any insight
Here's the code:
status_id = <some_status_id>
response = twitter.get_retweets(status_id, 100)
which results in the following error
TypeError: get_retweets() takes 1 positional argument but 3 were given
I tried to run without arguments as in
response = twitter.get_retweets()
and then I get an error from Twitter saying
twython.exceptions.TwythonError: Twitter API returned a 404 (Not Found), Sorry, that page does not exist
Is this a bug?
Solved, the status_id must be passed as a named parameter
status_id = <some_status_id>
response = twitter.get_retweets(id=status_id) # 100 is already the max available
I have been working with classes however when ever I try to call an object within a class, I keep getting a message saying that the call takes no arguments. A simple example is in the following where I try to call a card, however it will not show. Do you have any idea as to what can be causing the issue?
class Card(object):
def _init_(self, symbol, rank):
self.symbol = symbol
self.rank = rank
def show(self):
print("{} of {}".format(self.rank, self.symbol))
card = Card("clubs", 6)
card.show(self)
The following is the error that appears:
card = Card("clubs", 6)
TypeError: Card() takes no arguments
You need to name the constructor method __init__, with two underscores on either side, not _init_.
As answered by #jwodder, you have to use __init__. Also while calling the show() you should call card.show().
I've been doing a rather basic project in my fundamentals of software development class (I'll apologize in advance for my code), it's basically making a snakes and ladders which generates random snakes and ladders.
The error starts at around line 66, with the specific error being:
if FirstPlayerPosition > 99:
TypeError: '>' not supported between instances of 'NoneType' and 'int'
Here's my github link to it, anyone can lend a hand?
def CheckForSnake(t):
if t in SnakePositions:
t -= 10
print("Oops! You've been bitten, go down 10 cells. Your new position is: %s" %(t))
return t
else:
return t
CheckForSnake function had a chance to not return if t isn't in SnakePositions same goes for the CheckForLadder function. You'll need to return something for when the if statement won't get called.
Running my script, I get the following error for some files:
COMError: (-2146822496, None, ('The file appears to be corrupted.',
'Microsoft Word', 'wdmain11.chm', 25272, None))
I have imported comtypes, and I wish to do an exception when this error occurs, so I do the following:
try:
code...
except comtypes.COMError:
pass
But it seems that Python does not recognize the exception, as it produces the same COMError as before.
Any suggestions on how to solve this problem? Thanks.
You probably need to show some more of your code in order for anyone to help you. I've run into a similar issue, but my application is a little different. I'll try my best to assist.
You need to actually handle the error that occurs.
So when you get the exception, you need to do something like this:
assuming this is your error:
COMError: (-2146822496, None, ('The file appears to be corrupted.', 'Microsoft Word', 'wdmain11.chm', 25272, None))
except comtypes.COMError as ce:
# get the error information
target_error = ce.args # error in a tuple form
# target_error[0] -> -2146822496
# target_error[1] -> None
# target_error[2] -> 'The file appears to be corrupted.', 'Microsoft Word', 'wdmain11.chm', 25272, None
# target_error[2] is another tuple made up of
# [2][0] -> 'The file appears to be corrupted.'
# [2][1] -> 'Microsoft Word'
# [2][2] -> 'wdmain11.chm'
# [2][3] -> 25272
# [2][4] -> None
if target_error[2][0] == 'The file appears to be corrupted.':
print("# handle your error here inside this if statement")
The point is that once you get the actual error, you can then do something to handle it accordingly.
Again, without seeing your code its difficult to offer any more advice, but you could handle the error based on the Application Type ('Microsoft Word') or the error code ('The file appears to be corrupted.')