_tkinter.TclError: invalid command name ".entry#" - python

I've been coding in python using tkinter and came across an exception from the tinter library.
Since I don't know exactly what the error means, it is hard for me to debug my program. I was wondering if someone could outline the error and suggest what may have caused it, so that I know what to look for when debugging my program. _tkinter.TclError: invalid command name ".entry#" (The hash represents a number).
I have an image showing the navigation through my program that causes the error if it helps.
Basically, the program will only let me view a sub-menu in the "record" section once, each time I run it, when it should let me enter them as many times as I need to.

You should include the error as text and not as unreadable image.
Based on the error message, you're trying to call .get() on an Entry that doesn't exist anymore. Maybe the parent window has been destroyed/closed and the entry is not there anymore. Or maybe it is just a context thing... hard to tell without the code.
If you can't figure out, please edit your question and add a MCVE, then I will edit my answer with more specific information.

Related

How to use the control_click function with pyautoit?

I am trying to simulate mouseclicks with python, without using my actual mouse. I have found the autoit library and the control_click function seems to do exactly what I want. However, I am not really sure how to use the parameters? I have read through so many posts and not a single one helped me really out. This is the best I have so far:
autoit.control_click("Bluestacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]", click=1,x=500,y=500)
The error that I get: autoit.autoit.AutoItError: send click message failed
I have tried to use the AutoIt3 Window Info program, but the text where the controlID is supposed to be is just a blank box...what am I supposed to do?

message that pops up while writing python code on vscode

I am not sure what it is actually called. I am a beginner. I am learning python and using VS Code as my code editor. But when I write codes the message in the red circle highlighted in the screenshot pops up. It's kind of annoying.
Can someone please help me with it? I don't know what it is called and would like to turn it off.
That pop up just shows the structure of the function you are using. It includes parameter hints.
In the image it is showing the structure of print function. It's a useful feature to be honest.
Press esc to cancel out of an individual popup, or set"editor.parameterHints.enabled": false to disable it entirely.
So, that box you have there is the documentation of the method you are calling. In this case, print(). It's actually quite useful. It'll give you a quick description of the parameters that you can pass into the function. For more confusing functions, the auto-documentation is a must have. But, of course, it is up to you.
You can disable it by setting "editor.parameterHints.enabled" to false in your .json
This is a function provided by VS Code to display information such as method parameters. You can turn it off in settings.
Click the gear icon in the lower left corner and select Settings,
then search for parameterhints, and uncheck the options in the picture.
In addition, as mentioned above, you can also add the following configuration to the settings.json file to achieve the same effect.
"editor.parameterHints.enabled": false

PyQt5 Display Function Output in Text Edit [duplicate]

This question already has an answer here:
Add more than one line to a QTextEdit PyQt
(1 answer)
Closed 4 years ago.
I'm attempting to create a GUI for an application that reads lines of text from a file onto a Plain Text Edit in PyQt5. I'm very new to PyQt5 and created this GUI through the Designer in an attempt use PyQt5 to upgrade the GUI of an application I made using Tkinter. I know the names of the "widgets" I need to utilize, but I don't know the proper way to write and format the code. Below is an example of what I'm trying to do, but rather than display the text in the Text Edit, I am simply printing it out to the Python Shell. It works fine.
self.pushButton.clicked.connect(self.Display_Tweets)
def Display_Tweets(self):
readtweets = open("Tweetfile", "r")
tweetlist = readtweets.readlines()
for x in tweetlist:
print(x)
readtweets.close()
This prints to Shell what I want displayed in the text edit box when I click the button, so all I should need to do is tell it to display "x" on the Text Edit, rather than print it. Since I am new to PyQt5, I don't actually know the proper syntax for this, nor can I find any relevant up-to-date documentation.
So when I try and change the function to instead display the lines of the file on a Plain Text Edit widget I run into issues that I am pretty sure are because I am messing up the "grammar". The name of the Plan Text Edit widget is "plainTextEdit", but I'm not sure how to add text to it. If I run the code below the GUI closes when I press the button. Again the above code prints out to the Shell what I want displayed by the Text Edit, I just don't know how to get it into the Text Edit. I've tried many variations on what I've shown here, but they all end with the GUI just closing on me.
self.pushButton.clicked.connect(self.Display_Tweets)
def Display_Tweets(self):
readtweets = open("Tweetfile", "r")
tweetlist = readtweets.readlines()
for x in tweetlist:
self.plainTextEdit.append(x)
readtweets.close()
What I'm trying can be accomplished in tkinter if you have a Text Edit box called "DisplayTweets" using the code below. For tkinter you simply write the name of the text edit box, use the insert function, and then in the parantheses tell it where to add the line of text (in the code below I add it to the end of the text box) and then you tell it what to add. So I've got this working in Tkinter, I just want to know how to do the same thing in PyQt5 and I haven't been able to find a good resource yet.
def Display_Tweets():
readtweets = open("Tweetfile", "r")
tweetlist = readtweets.readlines()
for x in tweetlist:
DisplayTweets.insert(END, x)
readtweets.close()
I want to add that I'm not sure why the user "eyllanesc" keeps referring this as a duplicate question of how to add multiple lines in a PlainTextEdit. This is a question of how to add any line in a PlainText Edit as when I tried my GUI would close. Never did I have a problem of adding only one line to a PlainTextEdit. I get I'm new here, but I'm not going to let you try and walk over me because of it. There are many new users struggling to learn the same things I am and you are not helping by referring users to a different question than the one I am asking. Any new users please refer to the answers of the user "Lt Worf" instead of ellyanesc. Lt Worf answered the question and gave incredibly good resources along with his answer.
PyQt is just a generated wrapper around Qt, so you need to use the Qt documentation for all the Qt objects you use.
For setting text, you can use setText('blabla')
http://doc.qt.io/qt-5/qtextedit.html#setText
It supports both HTML for formatted text, or plain text.
To append text at the end, I do something like this
txt.moveCursor(QtGui.QTextCursor.End)
txt.insertHtml(data + '<br>')
txt.moveCursor(QtGui.QTextCursor.End)
if I want to use HTML, otherwise .append('blabla') also works.
The moving cursor part is not necessary for append, but it's nice because it will make your text box scroll down as you keep adding stuff.
Here is the answer for anyone else with a similar problem. LtWorf answered my question, and the documentation he sent had the answer within it. Obviously, I just answered the question for myself so I'm no expert, but I will answer in a way aimed at newbie idiots like myself. In my bad code where I write
self.plainTextEdit.append(x)
I fail to tell the computer what type of text to expect. Instead I need to write something like the code below, which tells it to append the output as plain text.
self.plainTextEdit.appendPlainText(x)
Or I can tell the computer to append the output as Html.
self.plainTextEdit.appendHtml(x)

PyGTK "assertion GTK_IS_WINDOW failed

I'm trying to build a web browser using PyGTK and PyWebKit
However, I'm pretty sure my question only concerns PyGTK
I have a custom gtk.Notebook class, with an "add tab" button as the last tab.
When I click it, it gives me the error
/home/ruiqimao/workspace/PyBrowser/src/browser/__init__.py:161: GtkWarning: IA__gdk_window_get_cursor: assertion `GDK_IS_WINDOW (window)' failed gtk.main()
twice.
And then, my new tab won't show up.
I have no idea what is going on, so here is my whole code
If any of you could help me, that would be great!
Thanks!
[EDIT]: Just found out that the problem lies in the w.show_all() line
What could this mean?
This question has been sitting in "unanswered" for months, without any answer. However, the problem was indeed solved (see comments). Thus, as a service to get this question OUT of "unanswered", I'll restate the apparent answer. If anyone else can top me, pleeeeeeeease do. :)
You forgot to show the new tab.
Thank you, and goodnight. :)

python win32api.LoadKeyboardLayout(), doesnt change language in IDLE shell?

Can someone help me out please...I'm trying to start my first programming project. It will be implemented in python.
I need to have a textbox (which i am using wxpython for). If the user enters any text into this text box, then I want it to appear as arabic. I wanted to this by automagically changing the users Keyboard to an arabic layout when the cursor lands in the given text box.
So i found this pywin32 module, which has a function LoadKeyboardLayout()
So i am trying to test this in IDLE, to see if I can make it accept arabic text into IDLE, to see if it works. So I enter, into IDLE:
win32api.LoadKeyboardLayout('00000401',1)
This then returns, 67175425, the decimal equivalent of hex:'4010401' whcih I believe is the locale ID for Arabic. SO I think wow! I've done it, but when I try typing after this, in the IDLE window, it continues to type normal english characters.
Can someone please explain my errors and guide me towards a good solution.
UPDATE
Okay, I've been trying to solve this problem ever since posting the damn question.
No luck.
Then, I thought, "ok, screw it, instead of testing it quicly in IDLE, I will just try it out, in situ, in my source code for the project."
WTF - it worked first time, giving exact behaviour that I wanted.
Then I tried it in a different IDE, in the interpreted window, and again, IT WORKED straight away!
So clearly my issue is with IDLE, in its interpreting mode.
Can anyone explain why it doesn't work in the IDLE shell???
Keyboard layout setting in Windows is per-process (and inherited from the parent process)
IDLE runs your Python script in a background process separate from its GUI
So you have successfully changed the keyboard layout of the background Python process that is running your script, but not of IDLE's GUI.

Categories

Resources