代码:
import tkinter as tk
from tkinter import ttk
def create_gui():
# 创建Tkinter窗口
root = tk.Tk()
# 设置窗口标题
root.title("显示图片")
# 图片文件路径
image_path = 'path_to_your_image.jpg'
# 加载图片
img = load_image(image_path)
# 创建标签,并将图片作为背景
label = tk.Label(root, image=img)
# 放置标签
label.pack()
# 开始Tkinter事件循环
root.mainloop()
def calculate_distance(x1, y1, x2, y2):
distance = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
label_distance.config(text=f"The distance is: {distance}")
def on_entry_change(event):
x1 = float(entry_x1.get())
y1 = float(entry_y1.get())
x2 = float(entry_x2.get())
y2 = float(entry_y2.get())
calculate_distance(x1, y1, x2, y2)
root = tk.Tk()
root.title("Distance Calculator")
# 创建两组坐标输入框
frame_coords = tk.LabelFrame(root, text="Coordinates")
f