|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
源代码from tkinter import *
from pandas import read_csv
def create(label):
scale = Scale(
root, from_=1, to=100, orient=横向, length=550, label=label,
command=update
)
globals()[f'scale{label}'] = scale
def update(v):
global count
draw('Sun', v)
count += 1
def draw(planet, v):
r = radius[planet] * v / scale
canvas.create_oval(0, 0, r, r, fill=color[planet])
横向 = HORIZONTAL
root = Tk(className='Solar system scale')
root.geometry('600x775')
root.resizable(False, False)
canvas = Canvas(root, width=600, height=600, bg='black')
canvas.place(x=0, y=0)
create('大小')
create('距离')
scale大小.place(x=25, y=625)
scale距离.place(x=25, y=700)
count = 0
编号范围 = range(1, 10) # 太阳+水金地火木土天海
data = read_csv('data.csv', index_col=0)
color = data['color']
radius = data['radius']
distance = data['distance']
# 600像素 = 海王星距离
scale = distance['Neptune'] / 600 # 这是1像素代表的距离
update(114)
root.mainloop()
报错信息Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\34459\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\34459\Documents\python_programs\solar_system_scale_TKINTER.py", line 13, in update
draw('Sun', v)
File "C:\Users\34459\Documents\python_programs\solar_system_scale_TKINTER.py", line 17, in draw
r = radius[planet] * v / scale
TypeError: can't multiply sequence by non-int of type 'numpy.float64'
csvradius,color,distance
Sun,695500,yellow,0
Mercury,2440,gray,57909050
Venus,6051.8,orange,108209184
Earth,6372.8,blue,149597871
Mars,3390,red,227954150
Jupiter,71400,navajowhite,778547200
Saturn,57330,antiquewhite,1433649370
Uranus,25300,cyan,2876674083
Neptune,24553,blue,4503443662
from tkinter import *
from pandas import read_csv
def create(label):
scale = Scale(
root, from_=1, to=100, orient=横向, length=550, label=label,
command=update
)
globals()[f'scale{label}'] = scale
def update(v):
global count
draw('Sun', int(v)) # 通过滚动条获取到的 v 为字符串,要用 int 转成整数
count += 1
def draw(planet, v):
r = radius[planet] * v / scale
canvas.create_oval(0, 0, r, r, fill=color[planet])
横向 = HORIZONTAL
root = Tk(className='Solar system scale')
root.geometry('600x775')
root.resizable(False, False)
canvas = Canvas(root, width=600, height=600, bg='black')
canvas.place(x=0, y=0)
create('大小')
create('距离')
scale大小.place(x=25, y=625)
scale距离.place(x=25, y=700)
count = 0
编号范围 = range(1, 10) # 太阳+水金地火木土天海
data = read_csv('data.csv', index_col=0)
color = data['color']
radius = data['radius']
distance = data['distance']
# 600像素 = 海王星距离
scale = distance['Neptune'] / 600 # 这是1像素代表的距离
update(114)
root.mainloop()
|
|