I am attempting to create an app that allows me to generate a tune for a game I play. But regardless, my goal is to save and load data from a sqlite3 database. But what is happening instead is:
Traceback (most recent call last):
File "d:\Visual Studio\DRIFT_TUNER\gui.py", line 360, in <module>
app = Application(master=root)
File "d:\Visual Studio\DRIFT_TUNER\gui.py", line 16, in __init__
self.populate_list()
File "d:\Visual Studio\DRIFT_TUNER\gui.py", line 350, in populate_list
self.tunes_list.delete(0, tk.END)
AttributeError: 'Application' object has no attribute 'tunes_list'
That happens when I call a function populate_list() which is this:
def populate_list(self):
self.tunes_list.delete(0, tk.END)
for row in db.fetch():
self.tunes_list.insert(tk.END, row)
Here are the Pastebins of my two files:
gui.py: https://pastebin.com/aJ5qAwtS
db.py: https://pastebin.com/mp3RnVK2
populate_list() is supposed to clear the text in the Listbox, then fetch data from the database and insert that data row by row into the Listbox. I'm using Python 3.9.5 with tkinter and sqlite3.
Things I've tried:
Converting all indents to spaces, and all spaces to indents.
Redeclaring the tunes_list
I do not know fully what this error means in the first place so any help would be nice.
self.tunes_list is created in your load_window method. Your load_window is called only when the button (named self.load_button) is pressed. But as soon as you create your Application object, you try calling populate_list which uses self.tunes_list. Therefore, you create a variable only when the button is pressed but try accessing it before that.
You can solve this problem by adding self.tunes_list = tk.Entry() in your __init__ or idk whatever your tunes_list is
Related
I am making a project based on tkintermapview, but it throws the error when the following code is run.
import tkintermapview as tkmap
self.map = tkmap.TkinterMapView(self.__map_frame, width=self.__map_width,
height=self.__height, corner_radius=0)
# google normal tile server
self.map.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# google satellite tile server
# self.map.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# self.map.set_tile_server("http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.png") # painting style
self.map.pack(fill=tk.BOTH)
self.map.set_address("kathmandu")
if the last line i.e. set_address() is removed then it runs fine otherwise it throws the error.
following is the error message:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Exception ignored in: <function PhotoImage.__del__ at 0x7fa9e10ed510>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Process finished with exit code 0
I tried the following code as well to reproduce the error
from tkintermapview import TkinterMapView
root_tk = tkinter.Tk()
root_tk.geometry(f"{600}x{400}")
root_tk.title("map_view_simple_example.py")
# create map widget
map_widget = TkinterMapView(root_tk, width=600, height=400, corner_radius=0)
map_widget.pack(fill="both", expand=True)
# google normal tile server
map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
map_widget.set_address("chyasal")
root_tk.mainloop()
But this time the error is shown for the first time only. After that the program works correctly.
But again when I change the place to new location say set_address("Manang") again for the first launch, the same error is occured.
But this is not the case with all the places, I tried many different places inside the set_address() method, but only some of them caused the error.
I have one more question
My project should enable a user to pick the pick up and drop off location on the map and the map should calculate the shortest road and its distance(length of road) between the two locations.
Is tkintermapview good choice or is there a better way to display google map and implement this requirement in tkinter...?
I am writing code to make a translator using GUI. My program runs but when I try to translate text it throws the error AttributeError: 'NoneType' object has no attribute 'group'
My code
from tkinter import*
from tkinter import ttk
from googletrans import Translator,LANGUAGES
def change(text="type",src="English",dest="Hindi"):
text1=text
src1=src
dest1=dest
trans = Translator()
trans1 = trans.translate(text,src=src1,dest=dest1)
return trans1.text
def data():
s =comb_sor.get()
d =comb_dest.get()
msg = Sor_txt.get(1.0,END)
textget = change(text=msg,src=s,dest=d)
dest_txt.delete(1.0,END)
dest_txt.insert(END,textget)
root = Tk()
root.title("Translater")
root.geometry("500x800")
root.config(bg="#FFE1F3")
lab_txt=Label(root,text="Translator", font=("Time New Roman",40,"bold"),fg="#478C5C")
lab_txt.place(x=100,y=40,height=50,width=300)
frame=Frame(root).pack(side=BOTTOM)
lab_txt=Label(root,text="Source Text", font=("Time New Roman",20,"bold"),fg="#FFFF8A",bg="#FDA172")
lab_txt.place(x=100,y=100,height=20,width=300)
Sor_txt =Text(frame,font=("Time New Roman",20,"bold"),wrap=WORD)
Sor_txt.place(x=10,y=130,height=150,width=480)
list_text = list(LANGUAGES.values())
comb_sor = ttk.Combobox(frame,value=list_text)
comb_sor.place(x=10,y=300,height=20,width=100)
comb_sor.set("English")
button_change = Button(frame,text="Translate",relief=RAISED,command=data)
button_change.place(x=120,y=300,height=40,width=100)
comb_dest = ttk.Combobox(frame,value=list_text)
comb_dest.place(x=230,y=300,height=20,width=100)
comb_dest.set("English")
lab_txt=Label(root,text="Dest Text", font=("Time New Roman",20,"bold"),fg="#2E2EFF")
lab_txt.place(x=100,y=360,height=50,width=300)
dest_txt=Text(frame,font=("Time New Roman",20,"bold"),wrap=WORD)
dest_txt.place(x=10,y=400,height=150,width=480)
root.mainloop()
The error and stack trace
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\praful pawar\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\praful pawar\AppData\Local\Temp\ipykernel_9920\1422625581.py", line 19, in data
textget = change(text=msg,src=s,dest=d)
File "C:\Users\praful pawar\AppData\Local\Temp\ipykernel_9920\1422625581.py", line 10, in change
trans1 = trans.translate(text,src=src1,dest=dest1)
File "C:\Users\praful pawar\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\praful pawar\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\praful pawar\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\praful pawar\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
What it looks like
This image shows that my application is running but something is wrong:
This library's own documentation says (bold added by me):
I eventually figure out a way to generate a ticket by reverse engineering on the obfuscated and minified code used by Google to generate such token, and implemented on the top of Python. However, this could be blocked at any time.
It is designed to work around limitations that Google deliberately installed in Google Translate to make sure you use their official API (and presumably pay) to connect to their service programmatically.
I believe that what you are seeing today is that, as the author warned could happen at any time, it got blocked. The last release was two years ago, so Google has had plenty of time to patch the hole this library exploited.
PS: there's a ticket about this...
Well, I still think this library could get blocked at any time, but it turns out the library is still actively maintained, and they have a ticket open about this issue: https://github.com/ssut/py-googletrans/issues/354 I suggest you watch that ticket, maybe they will fix it.
I just tested the release candidate one reply mentions in the ticket, and it fixed the problem for me:
pip install googletrans==4.0.0rc1
might make your code work.
So I have tried to write a small config file for my script, which should specify an IP address, a port and a URL which should be created via interpolation using the former two variables. My config.ini looks like this:
[Client]
recv_url : http://%(recv_host):%(recv_port)/rpm_list/api/
recv_host = 172.28.128.5
recv_port = 5000
column_list = Name,Version,Build_Date,Host,Release,Architecture,Install_Date,Group,Size,License,Signature,Source_RPM,Build_Host,Relocations,Packager,Vendor,URL,Summary
In my script I parse this config file as follows:
config = SafeConfigParser()
config.read('config.ini')
column_list = config.get('Client', 'column_list').split(',')
URL = config.get('Client', 'recv_url')
If I run my script, this results in:
Traceback (most recent call last):
File "server_side_agent.py", line 56, in <module>
URL = config.get('Client', 'recv_url')
File "/usr/lib64/python2.7/ConfigParser.py", line 623, in get
return self._interpolate(section, option, value, d)
File "/usr/lib64/python2.7/ConfigParser.py", line 691, in _interpolate
self._interpolate_some(option, L, rawval, section, vars, 1)
File "/usr/lib64/python2.7/ConfigParser.py", line 716, in _interpolate_some
"bad interpolation variable reference %r" % rest)
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'
I have tried debugging, which resulted in giving me one more line of error code:
...
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7fc4d32c46e0> ignored
Here I am stuck. I don't know where this _remove function is supposed to be... I tried searching for what the message is supposed to tell me, but quite frankly I have no idea. So...
Is there something wrong with my code?
What does '< function _remove at ... >' mean?
There was indeed a mistake in my config.ini file. I did not regard the s at the end of %(...)s as a necessary syntax element. I suppose it refers to "string" but I couldn't really confirm this.
My .ini file for starting the Python Pyramid server had a similar problem.
And to use the variable from the .env file, I needed to add the following: %%(VARIEBLE_FOR_EXAMPLE)s
But I got other problems, and I solved them with this: How can I use a system environment variable inside a pyramid ini file?
My app is in VB.Net. I have a textbox. The user writes a piece of Python code init. I want to run this code. For example, the code in textbox is something like this:
print 7*7
the result of running this code in Python is 49. But if the user forgets a space and writes:
print7*7
the result of running this code in Python is:
Traceback (most recent call last):
File "vm_main.py", line 33, in <module>
import main
File "/tmp/vmuser_jrlbqyaetu/main.py", line 8, in <module>
print7*7
NameError: name 'print7' is not defined
Now I want to save the result of running code (error or correct data) in a string in VB.Net. Questions:
What is the data type of the result of running the code?
Is it possible to access it?
Is it possible to save it? Is it possible to save it in a string? If yes, how?
You can try this:
import sys
f = open('output.txt', 'w')
sys.stdout = f
###############
#your code here
##############
And than all outputs will be written in ouput?txt
I write a program that can open a particular file, i.e., a Flash file, positioning it at particular position and closing it(not minimizing but exitting).
The first second target is ok by os.startfile('file.swf'), finding its hwnd by win32gui.FindWindow(None, file.swf) and positioning it by win32gui.MoveWindow(hwnd,0,0,800,600,True), however, the win32gui.DestroyWindow(hwnd) can't work and I don't know why.
Here is the error message below:
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
win32gui.DestroyWindow(hwnd1)
error: (5, 'DestroyWindow', '\xa6s\xa8\xfa\xb3Q\xa9\xda\xa1C')
What is wrong with it? How to fix it?
edit:
my code is:
import win32gui
import os
"""
monitoring a folder which will be updated per one miniute
if the temperature changed the program will open a particular file to display
"""
FLASH_PATH="santa"
PIC_PATH=""
TEMP_PATH="Temperatures/"
file_name="led_20.swf"
filePath=os.path.join(FLASH_PATH,file_name)
os.startfile(filePath)
hwnd=win32gui.FindWindow(None,file_name)
win32gui.MoveWindow(hwnd,0,0,800,600,True)
"""
display it for a few minute and close it
"""
Error 5 is ERROR_ACCESS_DENIED. DestroyWindow() can only be called by the thread that created the window. Post or send a WM_DESTROY message instead.