以下是使用 Python Tkinter 创建 360x270 窗口并添加图片和文字的示例代码:

import tkinter as tk

root = tk.Tk()
root.geometry('360x270')

# 加载图片
image_path = 'image.jpg'
image = tk.PhotoImage(file=image_path)

# 显示图片
label_image = tk.Label(root, image=image)
label_image.pack()

# 添加文字
label_temp = tk.Label(root, text='温度', font=('Arial', 16))
label_temp.place(x=55, y=62)

label_weather = tk.Label(root, text='天气', font=('Arial', 16))
label_weather.place(x=55, y=105)

root.mainloop()

代码解释:

  1. 导入 tkinter 库,创建 Tk 对象,并设置窗口大小为 360x270。
  2. 使用 PhotoImage 类加载图片,并使用 Label 类显示图片。
  3. 使用 Label 类添加 '温度' 和 '天气' 文字,并使用 place 方法指定文字位置。
  4. 使用 root.mainloop() 运行主循环,显示窗口。

通过以上代码,我们可以创建一个包含图片和文字的 360x270 窗口。

Python Tkinter 创建 360x270 窗口并添加图片和文字

原文地址: https://www.cveoy.top/t/topic/nflq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录