我目前正在开发一个 tkinter (GUI) 项目,该项目接收用户的平均值并将其返回给他们。我希望使用 PIL 库在我的父窗口中显示图像。昨天这个库工作正常并在目录中找到我的图像,但今天它似乎无法找到目录,有人可以帮助我并指导我。我不知道为什么 PIL 库今天表现得很好,通常它工作正常。(我试过重新安装文件,但没有帮助!)。
import tkinter
from PIL import Image, ImageTk
root = tkinter.Tk();
def showImg():
load = Image.open('Desktop\example.jpg')
render = ImageTk.PhotoImage(load)
img = tkinter.Label(root, image = render)
img.image = render
img.pack()
button = tkinter.Button(root, text='Click me to see an image.', command=showImg).pack();
root.title('Imaging test');
root.geometry('450x450');
root.mainloop();
Run Code Online (Sandbox Code Playgroud)
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\Pamal\Desktop\Documents\Python Folder\Python [Learn]\imaging_example.py", line 7, in showImg
load = Image.open('Desktop\example.jpg') …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用python在tkinter的帮助下构建一个GUI计算器.我设法设置了所有按钮,当我按下按钮时,它们与我的entry()栏进行交互(例如,按下按钮5和5出现在条目()中).
剩下要做的唯一事情就是执行条目()中出现的数学方程式.例如,如果我在条目栏中输入5 + 5*2,在更新后如何将答案显示在条目()中?所以基本上我要问的是有人帮助我实现这一目标!
我提供了下面的代码和计算器的屏幕截图.另外请不要将此作为副本报告或将此问题标记为帖子,(我正在重新提出这个问题,因为我在上一个问题上没有任何帮助,所以请帮助一个年轻的python程序员!).另外我要求你不要给我提供链接,因为我已经阅读了tkinter上的所有可能的链接,但仍然不知道我在做什么.
这是我的代码:
import sys
from tkinter import *
from PIL import Image, ImageTk
#ACTIONS:
def clear():
#Action: Clears the entry().
txtDisplay.delete(0,END);
return;
def update_Entry(inputValue):
#Updates the entry when a button is pressed.
currentText = num1.get();
update = num1.set(currentText + inputValue);
#Parent Window.
root = Tk();
root.title('Calculator ++ [1.7.2]');
root.geometry('350x450');
#Main entry.
num1 = StringVar();
txtDisplay = Entry(root, textvariable = num1, relief=RIDGE, bd = 10, width=33, insertwidth = 1, font = 40, justify=RIGHT);
txtDisplay.place(x=15, y=10);
txtDisplay.focus();
print(txtDisplay.get()) …Run Code Online (Sandbox Code Playgroud) 我正在基于C++ switch语句在线进行测验.我遇到了一个问题,我对switch语句的工作方式有了一个公平的理解,但这个问题对我来说完全没有意义.有人可以解释一下吗?

为什么答案是D而不是C?案例2:默认情况还是什么?该测验可在以下网址找到:http://www.cprogramming.com/tutorial/quiz/quiz5.html
我在网站上找到了以下代码,解释了如何使用python发送电子邮件(Hotmail/live).我可以理解一些代码,但大多数代码完全令人困惑.例如,s.starttls()表示/做什么,以及msg.as_string() ; 是先前定义的还是它做了什么?请帮帮我,因为我想了解这段代码(我想尽快制作一个gui应用程序版本).
请通过这个指导我....
PS - >我只有16岁所以请尽量让它听起来是可以理解的.
代码:
import email
import smtplib
msg = email.message_from_string('warning')
msg['From'] = "example@hotmail.fr"
msg['To'] = "example@hotmail.fr"
msg['Subject'] = "helOoooOo"
s = smtplib.SMTP("smtp.live.com",587)
s.ehlo()
s.starttls()
s.ehlo()
s.login('example@hotmail.fr', 'pass')
s.sendmail("example@hotmail.fr", "example@hotmail.fr", msg.as_string())
s.quit()
Run Code Online (Sandbox Code Playgroud) 我知道这似乎是一个副本,因为许多其他问题在堆栈上溢出,但老实说,我不理解任何这些问题.我只是需要有人为我澄清这一点,请不要标记这一点.我目前正在运行python 3.4.2,Windows 8.1
示例代码:
def function_A():
my_Name = "Pamal Mangat"
return my_Name
def function_B(name):
print("Hello " + name)
function_B(function_A.my_Name)
Run Code Online (Sandbox Code Playgroud) python ×4
c++ ×1
calculator ×1
email ×1
function ×1
hotmail ×1
python-3.4 ×1
python-3.x ×1
tkinter ×1