1.左上角我想设置个长图,如何在软件里面修改图片大小
2.文本框最下方出现了bug,超出了边框
```python
from tkinter import * # 引入tkinter库
from tkinter import filedialog
from PIL import Image # 引入PIL库的Imgae子模块
from PIL import ImageTk # 引入PIL库的ImageTk子模块
import qrcode # 引入qrcode库
def create_qrcode(text, filename):
"""
生成二维码图片
"""
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.ERROR_CORRECT_H,
box_size=5,
border=1
)
qr.make(fit=True)
qr.add_data(text)
# fill_color和back_color参数改变生成图片的格子颜色和背景颜色
img = qr.make_image(fill_color="Tan", back_color="white")
img.save(filename + '.png')
def save_qr():
# 获取文本框内的内容
text_input = t.get(0.0, "end")
# print(text_input)
if text_input == '\n':
text_input = 'http://www.baidu.com'
# 定义图片的名字为输入内容的第一个字符
img_name = filedialog.asksaveasfilename()
# print(img_name)
# 生成二维码图片
create_qrcode(text_input, img_name)
def callback():
# 获取文本框内的内容
text_input = t.get(0.0, "end")
if text_input == '\n':
text_input = 'http://www.baidu.com'
# 定义图片的名字为输入内容的第一个字符
img_name = text_input[0:1]
# 生成二维码图片
create_qrcode(text_input, img_name)
# 保存二维码图片至本地
img = Image.open(img_name + '.png')
# 设定图片大小
size = (320, 320)
if var.get() == "A":
size = (320, 320)
elif var.get() == "B":
size = (200, 200)
else:
size = (160, 160)
img = img.resize(size)
# 重新在窗体中显示新生成的二维码图片,覆盖刚才的图片
img = ImageTk.PhotoImage(img)
label.configure(image=img)
label.image = img
def print_selection():
print( 'u have select:' + var.get())
if __name__ == "__main__":
root = Tk() # 新建窗口
root.geometry("800x600") # 窗口大小
root.resizable(False, False) # 禁止改变窗口大小
root.title('二维码生成器') # 窗口标题
img = qrcode.make('https://www.baidu.com') # 将这个网站转换为二维码图片
img.save('d:\\hello.png') # 保存二维码图片到本地
img = Image.open('d:\\hello.png') # 打开本地二维码图片
img = ImageTk.PhotoImage(img) # 根据本地图片生成窗体图片
infoimg = Image.open('d:\\111.png')
img_show = ImageTk.PhotoImage(infoimg)
img_label = Label(root, image=img_show, width=300, height=60) # 图片
img_label.place(x=20, y=10) #
lbl = Label(root, text='图像\n大小', font=("黑体", 14), width=5, height=5, foreground='black') # 名称标签,前景色设红色
lbl.place(x=440, y=400) # 二维码图片位置
t = Text(root, width=36, height=18, font=("黑体", 16)) # 在窗体嵌入输入框
t.place(x=20, y=85) # 输入框的位置
btn1 = Button(root, text='点我生成二维码', width=20, font=("黑体", 14), command=callback) # 按钮,按钮相应函数 callback
btn1.place(x=120, y=520) # 按钮位置
btn2 = Button(root, text='保存', width=20, font=("黑体", 14), command=save_qr) # 按钮2
btn2.place(x=480, y=520) # 按钮位置
label = Label(root, image=img, width=400, height=400) # 嵌入二维码图片
label.place(x=400, y=45) # 二维码图片位置
var = StringVar()
r1 = Radiobutton(root, text='大', variable=var, value='A', command=print_selection)
r1.place(x=530, y=440)
r2 = Radiobutton(root, text='中', variable=var, value='B', command=print_selection)
r2.place(x=630, y=440)
r3 = Radiobutton(root, text='小', variable=var, value='C', command=print_selection)
r3.place(x=730, y=440)
var.set("A")
root.mainloop()
```