solution1_s() missing 1 required positional argument: 'sol_s1'
有人知道为什么这样不行吗?
它不会打印解决方案,而是产生以下错误:
Traceback (most recent call last):
File"C:\Program Files\Python34\lib\tkinter__init__.py", line 1533,
in call return self.func(*args)
TypeError: solution1_s() missing 1 required positional argument: 'sol_s1'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | solutions_s={ "sol_s1":"if this is happeing to you, there is a bug in the software. call up your supplier and they will try and troubleshoot the phone. make sure you have all the latest updates installed", "sol_s2":"these are all signs of a virus. the deleting of applications is virus munching on your data, and pop ups on your scren is also a virus symptom. immiditely use your antivirus to look for the problem or take it to a repair shop where they can delete the virus", "sol_app":"check if you have enogh storage on your device, if you dont and that was the problem, then see if you can get a storage upgrade. However, if it isnt there is a good chance you have a virus on your phone. scan your phone with an antivirus, or let your local repair shop do it", "sol_pop":"if the pop ups are on a web browser, this is normal. try getting an ad blocker if it is bothering you, but do not click on them. however, if it is happening on the main screen, you have contracted a virus. use your antivirus orget it fixed at a repair shop", "sol_s3":"this is another sign of a software fault. the only one who can fix this is your supplier. contact them as soon as possible"} def solution1_s(sol_s1): label20=Label(screen,text=solutions_s[sol_s1]) label20.pack() sys.exit() def solution2_s(sol_s2): label22=Label(screen,text=solutions_s[sol_s2]) label22.pack() sys.exit() def solution_app(sol_app): label23=Label(screen,text=solutions_s[sol_app]) label23.pack() sys.exit() def solution_pop(sol_pop): label24=Label(screen,text=solutions_s[sol_pop]) label24.pack() sys.exit() def solution3_s(sol_s3): label26=Label(screen,text=solutions_s[sol_s3]) label26.pack() sys.exit() |
当您像这样在函数头中放置变量时:
1 | def solution1_s(sol_s1): |
python希望您给它传递一个参数(可以是任何参数),并在该函数的范围内将其命名为
但是,您似乎希望在脚本中声明的字典
试试这个:
1 2 3 4 | def solution1_s(): label20=Label(screen,text=solutions_s['sol_s1']) label20.pack() sys.exit() |
以下是一些关于范围和口述的深入讨论的阅读材料:
作用域
辞典