根据欧姆定律,制作I=U/R计算电流的代码
import tkinter as tk
from tkinter import ttk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib as mpl
plt.rcParams['font.family'] = 'SimHei'
class App:
def __init__(self, root):
self.root = root
self.resistance_value = tk.StringVar()
self.voltage = 10.0
self.entry = ttk.Entry(root, textvariable=self.resistance_value)
self.entry.grid(row=0,column=1)
self.entry.bind('<Return>', self.update_light_bulb)
self.figure, self.ax = plt.subplots(figsize=(5, 4), dpi=100)
self.canvas = FigureCanvasTkAgg(self.figure, self.root)