import tkinter as tk
from tkinter import ttk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
class BalloonAndCrosshairsApp:
def __init__(self, root):
self.root = root
self.root.title("Main Window")
self.show_input_button = tk.Button(root, text="Show Input Form", command=self.show_input_form)
self.show_input_button.pack(padx=10, pady=10)
self.input_window = None
self.x_entry = None
self.y_entry = None
self.points = []
def show_input_form(self):
self.input_window = tk.Toplevel(self.root)
self.input_window.title("Coordinate Input")
self.x_label = tk.Label(self.input_window, text="X:")
self.x_label.grid(row=0, column=0, padx=5, pady=5)
self.x_entry = tk.Entry(self.input_window)
self.x_entry.grid(row=0, column=1, padx=5, pady=5)
self.y_label = tk.Label(self.input_window, text="Y:")
self.y_label.grid(row=1, column=0, padx=5, pady=5)
self.y_entry = tk.Entry(self.input_window)
self.y_entry.grid(row=1, column=1, padx=5, pady=5)
self.add_button = tk.Button(self.input_window, text="Add Point", command=self.add_point)
self.add_button.grid(row=2, columnspan=2, padx=5, pady=5)
self.plot_button = tk.Button(self.input_window, text="Plot Points", command=self.plot_points)
self.plot_button.grid(row=3, columnspan=2, padx=5, pady=5)
def add_point(self):
x = float(self.x_entry.get())
y = float(self.y_entry.get())
self.points.append((x, y))
self.x_entry.delete(0, tk.END)
self.y_entry.delete(0, tk.END)
def plot_points(self):
if not self.points:
return
plot_window = tk.Toplevel(self.root)
plot_window.title("Plot")
x_coordinates = set()
y_coordinates = set()
for x, y in self.points:
x_coordinates.add(x)
y_coordinates.add(y)
fig = Figure(figsize=(5, 4))
ax = fig.add_subplot(111)
balloon_counter = 1
for y in y_coordinates:
for x in x_coordinates:
ax.plot(x, y, 'o', label=f'X{balloon_counter}')
balloon_counter += 1
for y in y_coordinates:
ax.axhline(y, color='red', linestyle='--')
for x in x_coordinates:
ax.axvline(x, color='blue', linestyle='--')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.legend()
ax.grid(True)
canvas = FigureCanvasTkAgg(fig, master=plot_window)
canvas.get_tk_widget().pack()
root = tk.Tk()
app = BalloonAndCrosshairsApp(root)
root.mainloop()
Pydroidだと表示されたウィンドウをいじれない。