第一排喷口显示不完整,可能是frame6和canvas6设置的问题?请问怎么改呀!非常感谢!
KG01到KG05随便输入五个1就行
KG01,KG02,KG03,KG04,KG05=map(float,input().split())
import tkinter as tk
from tkinter import *
import random
import time
window = Tk()
window.title("可视化界面")
# 设置宽度高度 和距离屏蔽左侧上侧的长度
window.geometry('1200x800+600+200')
# 不可修改高度和宽度
window.resizable(True,True)
# 用户的原始设置
a=float()
x1=float(75)
y1=float(170)
x2=float(250)
y2=float(270)
''' 下面是所有的布局'''
# 分上下
frame = Frame(window)
frame.pack(side='top',)
frame_bottom = Frame(window)
frame_bottom.pack(side='bottom')
# 设置各个框架的大小和设置不可被继承组件修改高度和宽度
frame1 = tk.Frame(master=frame,width=350, height=350, bg="red")
frame1.pack_propagate(0)
frame2 = tk.Frame(master=frame,width=350, height=350, bg="red")
frame2.pack_propagate(0)
frame3 = tk.Frame(master=frame,width=500, height=200, bg="yellow")
frame3.pack_propagate(0)
frame4 = tk.Frame(master=frame_bottom,width=350, height=450, bg="blue")
frame4.pack_propagate(0)
frame5 = tk.Frame(master=frame_bottom,width=350, height=450, bg="blue")
frame5.pack_propagate(0)
frame6 = tk.Frame(master=frame_bottom,width=500, height=450, bg="green")
frame6.pack_propagate(0)
# 左对齐
frame1.pack( side='left', expand=True, fill=tk.BOTH )
frame3.pack( side='left', expand=False, fill=tk.BOTH)
frame2.pack( side='left', expand=True, fill=tk.BOTH )
frame4.pack( side='left', expand=True, fill=tk.BOTH)
frame6.pack( side='left', expand=True, fill=tk.BOTH)
frame5.pack( side='left', expand=True, fill=tk.BOTH)
# 下面开始嵌入用户的代码
# 两边的按钮
# 基于不同的frame画即可
canvas=tk.Canvas(frame1)
line1= canvas.create_line(200, 100,200, 300,width=36,fill='gray',arrow="both")
line2= canvas.create_line(100,200, 300, 200, width=36,fill='gray',arrow="both")
canvas.pack( expand=True, fill=tk.BOTH) # 设置范围扩张和权限填充
canvas2=tk.Canvas(frame2)
line3= canvas2.create_line(200,100,200, 300,width=36,fill='gray',arrow="both")
line4= canvas2.create_line(100,200, 300, 200, width=36,fill='gray',arrow="both")
canvas2.pack( expand=True, fill=tk.BOTH)
# 右下角 电机
canvas4=tk.Canvas(frame5)
# 注意是继承的 frame4 所以和其他的框架是分开的
#前2个左上角坐标 后2个右下角坐标
rect331=canvas4.create_rectangle(100,200,120,300,fill='white')#电机背景
rect332=canvas4.create_rectangle(200,200,220,300,fill='white')
rect333=canvas4.create_rectangle(300,200,320,300,fill='white')
canvas4.create_text(90,200,text='1',font=('黑体', 12))#电机静态文字
canvas4.create_text(90,250,text='0',font=('黑体', 12))
canvas4.create_text(90,300,text='-1',font=('黑体', 12))
canvas4.create_text(190,200,text='1',font=('黑体', 12))
canvas4.create_text(190,250,text='0',font=('黑体', 12))
canvas4.create_text(190,300,text='-1',font=('黑体', 12))
canvas4.create_text(290,200,text='1',font=('黑体', 12))
canvas4.create_text(290,250,text='0',font=('黑体', 12))
canvas4.create_text(290,300,text='-1',font=('黑体', 12))
canvas4.create_text(103,158,text='电机x',font=('黑体', 12))
canvas4.create_text(203,158,text='电机y',font=('黑体', 12))
canvas4.create_text(303,158,text='电机z',font=('黑体', 12))
canvas4.pack( expand=True, fill=tk.BOTH)
#左下静态文字
canvas5=tk.Canvas(frame4)
canvas5.pack( expand=True, fill=tk.BOTH)
canvas5.create_text(75,240,text='测定重心:',font=('黑体', 12))
canvas5.create_text(65,270,text='加速度传感器:',font=('黑体', 12))
# 下方中间
canvas6=tk.Canvas(frame6)
for i in range(8):
# 10-60为高度
# *80为间隔 20为宽度
ii=i+1
canvas6.create_text(25+i*60,0,text='喷口%d'%(ii),font=('黑体', 12))#喷口静态文字
canvas6.create_text(25+i*60,120,text='喷口%d'%(ii),font=('黑体', 12))
canvas6.create_text(25+i*60,240,text='喷口%d'%(ii),font=('黑体', 12))
canvas6.create_rectangle(10+i*60,10,10+i*60+20,70,fill='white') #喷口白色背景(但是黑色必须一个个手打,不可以用for)
canvas6.create_rectangle(10+i*60,130,10+i*60+20,190,fill='white')
canvas6.create_rectangle(10+i*60,250,10+i*60+20,310,fill='white')
canvas6.create_text(5+i*60,10,text='1',font=('黑体', 12))
canvas6.create_text(5+i*60,130,text='1',font=('黑体', 12))
canvas6.create_text(5+i*60,250,text='1',font=('黑体', 12))
canvas6.create_text(5+i*60,70,text='0',font=('黑体', 12))
canvas6.create_text(5+i*60,190,text='0',font=('黑体', 12))
canvas6.create_text(5+i*60,310,text='0',font=('黑体', 12))
canvas6.create_rectangle(10,10,30,70,fill='black') #喷口动态黑部分(1-8)
canvas6.create_rectangle(70,10,90,70,fill='black')
canvas6.create_rectangle(130,10,150,70,fill='black')
canvas6.create_rectangle(190,10,210,70,fill='black')
canvas6.create_rectangle(250,10,270,70,fill='black')
canvas6.create_rectangle(310,10,330,70,fill='black')
canvas6.create_rectangle(370,10,390,70,fill='black')
canvas6.create_rectangle(430,10,450,70,fill='black')
canvas6.create_rectangle(10,130,30,190,fill='black') #喷口动态黑部分(9-16)
canvas6.create_rectangle(70,130,90,190,fill='black')
canvas6.create_rectangle(130,130,150,190,fill='black')
canvas6.create_rectangle(190,130,210,190,fill='black')
canvas6.create_rectangle(250,130,270,190,fill='black')
canvas6.create_rectangle(310,130,330,190,fill='black')
canvas6.create_rectangle(370,130,390,190,fill='black')
canvas6.create_rectangle(430,130,450,190,fill='black')
canvas6.create_rectangle(10,250,30,310,fill='black') #喷口动态黑部分(17-24)
canvas6.create_rectangle(70,250,90,310,fill='black')
canvas6.create_rectangle(130,250,150,310,fill='black')
canvas6.create_rectangle(190,250,210,310,fill='black')
canvas6.create_rectangle(250,250,270,310,fill='black')
canvas6.create_rectangle(310,250,330,310,fill='black')
canvas6.create_rectangle(370,250,390,310,fill='black')
canvas6.create_rectangle(430,250,450,310,fill='black')
canvas6.pack( expand=True, fill=tk.BOTH)
while(True):
# 动态操作杆
x1=random.uniform(-1, 1)
rect1=canvas.create_rectangle(200+100*x1,182,200+100*x1,218,width=3,fill='black')
rect2=canvas2.create_rectangle(200+100*x1,182,200+100*x1,218,width=3,fill='black')
stick_y1=canvas.create_rectangle(182,200+100*x1,218,200+100*x1,width=3,fill='black')
stick_y2=canvas2.create_rectangle(182,200+100*x1,218,200+100*x1,width=3,fill='black')
time.sleep(0.1)
# 开关黑(作为背景,默认关,根据输入的数值以比例计算高度)
canvas3=tk.Canvas(frame3)
rect22=canvas3.create_rectangle(220,100,240,150,fill='black')
rect23=canvas3.create_rectangle(250,100,270,150,fill='black')
rect24=canvas3.create_rectangle(280,100,300,150,fill='black')
rect25=canvas3.create_rectangle(310,100,330,150,fill='black')
rect21=canvas3.create_rectangle(340,100,360,150,fill='black')
# 开关白(开)
if KG01==1:
rect12=canvas3.create_rectangle(220,100,240,150,fill='white')
if KG02==1:
rect13=canvas3.create_rectangle(250,100,270,150,fill='white')
if KG03==1:
rect14=canvas3.create_rectangle(280,100,300,150,fill='white')
if KG04==1:
rect15=canvas3.create_rectangle(310,100,330,150,fill='white')
if KG05==1:
rect11=canvas3.create_rectangle(340,100,360,150,fill='white')
canvas3.pack( expand=True, fill=tk.BOTH)
# 修改电机
x3=random.uniform(-1, 1)
rect441=canvas4.create_rectangle(100,250-50*x3,120,250,fill='black')
rect442=canvas4.create_rectangle(200,250-50*x3,220,250,fill='black')
rect443=canvas4.create_rectangle(300,250-50*x3,320,250,fill='black')
# 动态加速度数字
a=random.uniform(-1, 1)
a=round(a,3)
text1=canvas5.create_text(160,240,text= str(a),font=('黑体', 12))
# 动态重心数字
text2=canvas5.create_text(160,270,text= str(a),font=('黑体', 12))
#不断更新
time.sleep(0.5)
window.update()
canvas.delete(rect1)
canvas2.delete(rect2)
canvas4.delete(rect441)
canvas4.delete(rect442)
canvas4.delete(rect443)
canvas5.delete(text1)
canvas5.delete(text2)
canvas2.delete(stick_y2)
canvas.delete(stick_y1)
# #保持状态
window.mainloop()