第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將線的點(diǎn)移動(dòng)到特定位置?

如何將線的點(diǎn)移動(dòng)到特定位置?

慕的地6264312 2021-09-25 16:56:47
我正在嘗試使用 tkinter 在 python 中可視化正弦波加法,并且我正在嘗試在每個(gè)圓中心之間建立線,但是到目前為止我嘗試過(guò)的并沒(méi)有像我想象的那樣工作。有沒(méi)有辦法解決我嘗試過(guò)的問(wèn)題(見代碼),或者有辦法只移動(dòng)一條直線的一個(gè)坐標(biāo)點(diǎn)與另一個(gè)坐標(biāo)點(diǎn)嗎?如果您運(yùn)行它,您將在代碼中看到,我嘗試了一種方法,其中每次迭代前一行都被擦除并創(chuàng)建一個(gè)新行。當(dāng)我運(yùn)行代碼時(shí),就像我想要的那樣,每個(gè)圓圈的中心之間實(shí)際上有一條線,但事實(shí)是這些線持續(xù)存在并且不會(huì)自行擦除;出于某種原因,似乎 canvas.delete(line) 不像我預(yù)期的那樣工作。這是完整的代碼。有趣的部分是在 'updateline' 函數(shù)中,進(jìn)入 'act()' 函數(shù)。import mathimport tkinter as tk##important to know! -- the way I'm creating the circles is by setting an object, the bounds of the circle, depending on amplitude asked by user.##then the programs calculates the path of these bounds, depending on circles, amplitude, phase and frequency of the sine waves asked by the user from the tkinter GUI.##finally, the program creates and moves along this path a circle, representing visually the sine wave.top = tk.Tk()top.title('Superposition')choice = tk.Tk()choice.title('Parametres')f = tk.Frame(choice,bd=3)f.pack(side='top')g = tk.Frame(choice,bd=3)g.pack(side='bottom')tk.Label(f,text="nbre ondes:",width = 10).grid(row=0,column=0)sines = tk.Spinbox(f,from_=1,to=50,width=10,textvariable=tk.DoubleVar(value=2))sines.grid(row=0,column=1)sines.delete(0,5)sines.insert(0,2)delai = tk.Scale(g, orient='vertical', from_=100, to=1,resolution=1, length=100,label='delai')delai.grid(row=0,column=0)hauteur = tk.Scale(g, orient='vertical', from_=1100, to=100,resolution=100, length=100,label='fenetre')hauteur.grid(row=0,column=1)taillec1 = tk.Scale(g, orient='vertical', from_=3.5, to=0.1,resolution=0.1, length=100,label='taille')taillec1.grid(row=0,column=2)delai.set(20)hauteur.set(600)taillec1.set(1.5)def grilledechoix():    numberofsines = int(sines.get())    for i in f.grid_slaves():        if int(i.grid_info()["row"]) > numberofsines+2:            i.grid_forget()我預(yù)計(jì)一旦 updateline 函數(shù)再次調(diào)用自身,這些行就會(huì)消失,因?yàn)?'canvas.delete(line)' 行進(jìn)入了 updateline,我真的不明白它為什么會(huì)這樣做。無(wú)論如何,如果您有使線條移動(dòng)的解決方案,而無(wú)需在每次調(diào)用函數(shù)時(shí)創(chuàng)建和刪除它們,請(qǐng)隨時(shí)告訴我。
查看完整描述

1 回答

?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

如果我正確理解了問(wèn)題,我相信問(wèn)題出在這段代碼上:


canvas.after(delai, canvas.delete, line)

canvas.create_line(oldx0+dx0, oldy0+dy0, oldx1+dx1, oldy1+dy1)

canvas.after(delai, updateline, canvas, line, robj0, cent0, robj1, cent1)

它無(wú)法將新行重新分配給line下一次調(diào)用的變量。而是嘗試:


canvas.after(delai, canvas.delete, line)

line = canvas.create_line(oldx0+dx0, oldy0+dy0, oldx1+dx1, oldy1+dy1)

canvas.after(delai, updateline, canvas, line, robj0, cent0, robj1, cent1)

當(dāng)我運(yùn)行它時(shí),它消除了多余的線條。如果我錯(cuò)過(guò)了重點(diǎn),請(qǐng)告訴我。


查看完整回答
反對(duì) 回復(fù) 2021-09-25
  • 1 回答
  • 0 關(guān)注
  • 242 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)