L
L
L2018-12-06 16:14:28
Yii
L, 2018-12-06 16:14:28

Error in python, (tkinter library) can you help?

In general, I want to create a program to find out the weather, but when I click to find out, an error is displayed

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "pogodaGUI.py", line 59, in <lambda>
    return lambda : callback(id, tex)
  File "pogodaGUI.py", line 62, in callback
    s = 'Утром: ' + pogoda1 + ' ' + pogoda2 + ' Днём: ' + pogoda3 + ' ' + pogoda4
NameError: name 'pogoda1' is not defined

And here is the code
from tkinter import *
from tkinter.ttk import *
import requests, bs4
import sys
top = Tk()
#root = Tk()
###
#text = Text(width=25, height=5, bg="darkgreen", fg='white', wrap=WORD)
#text.pack()
#text = print ('Ага')
#text.pack ()
#root.mainloop()
# s = requests.get('https://sinoptik.com.ru/погода-)
# b = bs4.BeautifulSoup(s.text, "html.parser")
# p3=b.select('.temperature .p3')
# pogoda1=p3[0].getText()
# p4=b.select('.temperature .p4')
# pogoda2=p4[0].getText()
# p5=b.select('.temperature .p5')
# pogoda3=p5[0].getText()
# p6=b.select('.temperature .p6')
# pogoda4=p6[0].getText()

v = StringVar()
e = Entry(top, textvariable=v)
e.pack()
 
 
def get_value():
    print(v.get())
 
 
def clean_value():
    v.set("")

b1 = Button(top, text="Ваш город", width=10, command=get_value)
b2 = Button(top, text="очистить", width=10, command=clean_value)
 
b1.pack()
b2.pack()

def pogoda():
  global pogoda1
  global pogoda2
  global pogoda3
  global pogoda4
  s = requests.get('https://sinoptik.com.ru/погода-' + v)
  b = bs4.BeautifulSoup(s.text, "html.parser")
  p3=b.select('.temperature .p3')
  pogoda1=p3[0].getText()
  p4=b.select('.temperature .p4')
  pogoda2=p4[0].getText()
  p5=b.select('.temperature .p5')
  pogoda3=p5[0].getText()
  p6=b.select('.temperature .p6')
  pogoda4=p6[0].getText()

def cbc(id, tex):
    return lambda : callback(id, tex)

def callback(id, tex):
    s = 'Утром: ' + pogoda1 + ' ' + pogoda2 + ' Днём: ' + pogoda3 + ' ' + pogoda4
    tex.insert(END, s)
    tex.see(END)             # Scroll if necessary

# top = Tk()
tex = Text(master=top)
tex.pack(side=RIGHT)
bop = Frame()
bop.pack(side=LEFT)
for k in range(1):
    tv = 'узнать {}'.format(k)
    b = Button(bop, text=tv, command=cbc(k, tex))
    b.pack()

Button(bop, text='Свалить', command=top.destroy).pack()
###
# v = StringVar()
# e = Entry(top, textvariable=v)
# e.pack()
 
 
# def get_value():
#     print(v.get())
 
 
# def clean_value():
#     v.set("")

# b1 = Button(top, text="Ваш город", width=10, command=get_value)
# b2 = Button(top, text="очистить", width=10, command=clean_value)
 
# b1.pack()
# b2.pack()
###
top.mainloop()

Answer the question

In order to leave comments, you need to log in

7 answer(s)
S
Sanes, 2016-01-12
@egor_spk

Modx+Minishop+Editor role
In the admin panel there will be only a project tree and a media manager

S
Sergey, 2016-01-12
@gangstarcj

You can use any free CMS (even Joomla), you can attach Virtumart to it and disable the purchase function in it

D
Dmitry Bay, 2016-01-12
@kawabanga

1) Popular CMS are right for you. I once did simple projects on host cms free version.
2) there are options with platforms like insales. But it is relatively expensive.
3) to write yourself, you need to have an understanding of how the store will work, where it will grow, and so on. + to know at the proper level languages.

A
Alex, 2016-01-12
@streetflush

ANGULAR.JS in the tags is clearly superfluous. You can't deploy a light site on it.
I wrote for a similar solution myself. Took Slim and Bootstrap + jQuery. Maybe now they will throw rags, but it works smartly and adaptively.
I made the admin panel on the knee, but that's why it is the admin panel, that a person in it will not break anything on purpose.
I scratch my head from time to time, maybe all this should have been done on WordPress because it would be faster in development. But WP is not familiar and I do not know stones.

V
Vladimir Io, 2016-01-12
@vawsan

  1. There is such a subclass of CMS - called CMS on files. They are usually written in php and do not have a database, they are extremely simple and designed for small sites with a number of pages within a hundred or two.
    Search the internet.
  2. But if you need a database, then you can take Wordpress, use its admin panel, and do the output of melons with your own scripts, from the database, throwing out everything superfluous that it gives out by default.

C
Cyber_bober, 2016-01-12
@Cyber_bober

Take a look at LightCMS.
If you still take AngularJs, then a bunch of Angular + Mongo + Node.js will come out with the admin panel

I
Ivan, 2018-12-06
@leonid_073

def pogoda():
  global pogoda1

print(pogoda1)

I think you should first figure out why the code above is complete crap)
then read about the scope of variables in Python.
then read the debugger , the function simply does not see pogoda1 , as well as other variables. . "NameError: name 'pogoda1' is not defined"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question