Kivy window dont't show up - AttributeError: module 'collections' has no attribute 'namedtuple' - python-3.x

Why I'm getting this error --> AttributeError: module 'collections' has no attribute 'namedtuple'. Whats wrong with my code..
I'm using python 3.5.2 on windows. When I execute my code on IDLE it can run - show up the kivy window, but when I execute C:\POS\operator\python operator.py it failed.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class OperatorWindow(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
class OperatorApp(App):
def build(self):
return OperatorWindow()
if __name__ == "__main__":
OperatorApp().run()

It looks like your file name is at fault here since there's also a standard library module called operator. I've got the same error but when I renamed your sample code from operator.py to test.py, it worked normally.

Related

Error while restarting the Tkinter program dynamically by destroying root and recreating again by calling functions

import configparser
from tkinter import *
from tkinter import filedialog,messagebox
from tkinter.filedialog import asksaveasfile
from customtkinter import *
import os
import time
import wikipedia
config=configparser.ConfigParser()
config.read("config.ini")
def change_config():
messagebox.showinfo("Information","App is going to restart in few seconds")
print(mode.get())
print(color.get())
global location
config.set("THEME","mode",str(mode.get()))
config.set("VOICE","voice",str(gender.get()))
if color.get() =="pink":
location="C:/Users/DELL/Documents/python programs/notepad/custom_theme.json"
config.set("THEME","color",location)
else :
config.set("THEME","color",color.get())
with open("config.ini","w") as configfile:
config.write(configfile)
restart()
def main():
global root,label,frame1,config_color,config_mode,config_gender
root=CTk()
root.geometry("700x600")
root.resizable(0,0)
root.title("Notepad")
frame1=CTkFrame(root,width=150,height=580)
frame1.pack_propagate(False)
frame1.place(x=10,y=10)
config_color=config.get("THEME","color")
config_mode=config.get("THEME","mode")
config_gender=config.get("VOICE","voice")
set_appearance_mode(config_mode)
set_default_color_theme(config_color)
label=CTkLabel(root,text="File",width=520,height=40,font=("Algerian",30))
label.place(x=170,y=10)
global S
global text_area
text_area=CTkTextbox(root,height=580,width=520,)
text_area.place(x=170,y=60)
global button,commands,button_text
button_text="Settings"
commands=settings
button=CTkButton(frame1,text=button_text,command=settings)
button.pack(padx=10,pady=10)
root.mainloop()
def settings():
global submit,mode,color,config_color,config_mode,gender
window=CTkToplevel(root)
window.title("Settings")
window.geometry("200x300")
label1=CTkLabel(window,text="Mode").pack(pady=5)
mode=CTkOptionMenu(window,values=["light","dark"])
mode.pack(pady=5,padx=5,anchor=CENTER)
label2=CTkLabel(window,text="Color").pack(pady=5)
color=CTkOptionMenu(window,values=["pink","blue","green","dark-blue"])
color.pack(pady=5)
label3=CTkLabel(window,text="speech-gender").pack(pady=5)
gender=CTkOptionMenu(window,values=["male","female"])
gender.pack(pady=5)
submit=CTkButton(window,text="Submit",command=change_config)
submit.pack(pady=20)
window.mainloop()
if __name__=="__main__":
def restart():
time.sleep(5)
root.destroy()
main()
main()
I want to create a notepad , where we can change themes and colors.
I have made config.ini file where i save the current mode, color and the voice type for the notepad ( voicetype is for text-to-speech functionality that i have added here ) becuase while using customtkinter we can set default color theme and cannot change it once initialized in a program.
The program now save the selected preferences in config.ini file and grab it when run again.
I want the program to run again itself without having the need to explicitly run it again.
Though program is running i am still getting this error at backend:
invalid command name "2912423726080check_dpi_scaling"
while executing
"2912423726080check_dpi_scaling"
("after" script)
invalid command name "2912423728512update"
while executing
"2912423728512update"
("after" script)
invalid command name "2912423728448<lambda>"
while executing
"2912423728448<lambda>"
("after" script)
I want to know what this error means so that the users might not face problem in future while using this app.
Thanks in advance for helping.

Running Django with Pyto on iPad

I am trying to build my first Webb app using Django. I’m using my iPad because I am on the move a lot. Anyways, I’m trying to follow Django’s instructions for building a poll application. I got the server running but when i made the changes that should have printed the Hello World but its now its giving me a ModuleNotFoundError.
I’ve tried copy and pasting the lines of code from Django’s website and I’ve tried to type it in on my own.
ModuleNotFoundError: No module named 'WellnessApp'
import os
`import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'WellnessProject.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
#if __name__ == '__main__':
# main()
if __name__ == '__main__':
import background as bg
with bg.BackgroundTask() as b:
main()`

Importing a Class from another python file in Vscode

I have made this class in python3:
#!/usr/bin/env python3
class Post():
def __init__(self):
self.title="this is my title"
self.content= "this is some content"
self.author= "Ata"
And then wanted to import this class into another file named "app.py":
#!/usr/bin/env python
# importing class from post.py into app.py
from post import Post
post= Post()
post2= Post()
print (post.content)
but get this error:
ImportError: cannot import name 'Post'
what is the problem with the code?
Finally, I got my answer... The only thing that I had to do in order to import my class into another python file was that I should have saved it. that's all and after this everything works fine.

unittest is not working

I am trying to run a test using unit test by using python3 functional_tests.py -the file name- but i get
"----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK"
here is my code:
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def testcan_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title)
self.fail('finish test')
if __name__ == '__main__':
unittest.main(warnings='ignore')
i am using python 3.5.2
Are you doing the exercises in Test-Driven Development with Python? Are these Django tests? If they are Django tests, you can try the following:
python3 manage.py test functional_tests
Even so, the commenter states correctly that the if __name... portion of the code should not be indented. It should be fully on the left margin.

How not to call initialize at each request with Tornado

I want to set variables when starting my Tornado webserver, so I tried to override initialize on my RequestHandler class. But apparently, initialize is launched each time a request is made, according to the following code and its output:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def initialize(self):
print("Launching initialization...")
def get(self):
print("Get: {}{}".format(self.request.host, self.request.uri))
app = tornado.web.Application([=
(r"/.*", MainHandler)
])
def runserver():
import tornado.ioloop
app.listen(8080)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
runserver()
stdout:
~ ➤ ./redirector.py
Launching initialization...
Get: 127.0.0.1:8080/
Launching initialization...
Get: 127.0.0.1:8080/favicon.ico
Launching initialization...
Get: 127.0.0.1:8080/favicon.ico
Launching initialization...
Get: 127.0.0.1:8080/
This behavior is the complete contrary to what is written in the doc:
Hook for subclass initialization.
(Meaning it is called at the end of __init__)
So, does anybody know how to do what I want to ?
Thanks in advance.
It's not contrary to the doc; have a look at the Structure of a Tornado app section. A RequestHandler object is created for each request.
If you want code to be executed when the app is started only, subclass the Application class and override __init__, or just put it in your runserver function.

Resources