python tkinter怎么读_Tkinter GUI与阅读系列
開始工作了。這是密碼class Mainframe(tk.Frame):
def __init__(self,master,*args,**kwargs):
super(Mainframe,self).__init__(master,*args,**kwargs)
self.meter = Meter(self,height = 400,width = 400)
self.meter.setrange(20,90)
self.meter.pack()
tk.Scale(self, width = 15, from_ = 20, to = 90, orient = tk.HORIZONTAL,
command = self.setmeter).pack()
tk.Button(self,text = 'Quit',width = 15,command = master.destroy).pack()
tk.Button(self,text = 'Zoom',width = 15).pack()
self.setmeter(15)
def setmeter(self,value):
value = int(value)
self.meter.set(value)
class App(tk.Tk):
def __init__(self):
super(App,self).__init__()
self.title('My Meter')
Mainframe(self).pack()
root = App()
serBuffer =b""
aux=""
def readSerial():
serBuffer=b""
while True:
c = ser.read() # attempt to read a character from Serial
#was anything read?
if len(c) == 0:
#print("cero")
break
#else:
#print (len(c))
if c == b'\n' :
#we have all the info
aux = serBuffer.split(b" ")
print (aux[0]," ",aux[1])
miinstance= Mainframe()
miinstance.setmeter(50)
#root.update()
serBuffer = "" # empty the buffer
else:
serBuffer+=c# add to the buffer
#aux= str(serBuffer, 'utf-8')
root.after(700, readSerial) # check serial again soon
root.after(1000, readSerial)
root.mainloop()
順便說(shuō)一句,我知道我正在努力更新儀表。當(dāng)我收到完整的字符串(由檢測(cè)到)時(shí),我希望將該值傳遞給小部件以更新儀表。設(shè)置值的函數(shù)是setmeter,但是我的代碼
^{pr2}$
我得到這個(gè)錯(cuò)誤。第一行是接收到的串行字符(正確)b'90' b'0'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python 3.5\lib\tkinter\__init__.py", line 1535, in __call__
return self.func(*args)
File "C:\Program Files\Python 3.5\lib\tkinter\__init__.py", line 582, in callit
func(*args)
File "C:/Users/MARTIN/Documents/Personal/phyton/Nuevo anemometer/read_serie_v2.py", line 258, in readSerial
miinstance= Mainframe()
TypeError: __init__() missing 1 required positional argument: 'master'
我試圖把“master”作為參數(shù),但它說(shuō)“master”沒(méi)有定義。在
我的代碼(最初是從網(wǎng)絡(luò)上得到的)在圖形用戶界面中有一個(gè)比例tk.Scale(self,width = 15 ,from_ = 20, to = 90
,orient = tk.HORIZONTAL
,command = self.setmeter).pack()
當(dāng)我移動(dòng)它時(shí),它會(huì)更新儀表,但我不需要它。儀表應(yīng)該根據(jù)接收到的串行信息進(jìn)行更新。在
你知道怎么回事嗎?在
總結(jié)
以上是生活随笔為你收集整理的python tkinter怎么读_Tkinter GUI与阅读系列的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Adobe 祭出杀器,带「萤火虫」入局,
- 下一篇: 只狼影逝二度废弃地牢在哪里 废弃地牢玩法