Python:tkinter简易广告牌
生活随笔
收集整理的這篇文章主要介紹了
Python:tkinter简易广告牌
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用tkinter制作的簡易廣告牌,V1.0:
2020.07.19
功能:在窗口滾動顯示廣告.
import tkinter as tk global advertise advertise = ' 千里之行,始于足下 'def show_ad():global advertisetext1.delete(0.0,tk.END) #清除文本框內容text1.insert(tk.INSERT,advertise)text1.update()advertise = advertise[1:]+advertise[0]text1.after(500,show_ad) #實現文本框顯示刷新top = tk.Tk() #創建窗口對象的背景色 text1 = tk.Text(top) #創建文本 text1.pack() #將小部件放在主窗口中 show_ad()top.mainloop() #進入消息循環________________________________________________________________________________________________
使用tkinter制作的簡易廣告牌,V2.0:
2020.07.24
功能:用戶可以輸入廣告信息,并滾動廣告標語
import tkinter as tkclass Show_ad(tk.Frame):def __init__(self,parent=None,**kw):tk.Frame.__init__(self,parent,kw)self.advertise = tk.StringVar()self.textentry = tk.StringVar()entry = tk.Entry(frame1,textvariable=self.textentry)self.textentry.set('請輸入廣告信息')entry.pack()button = tk.Button(frame1,text='確定',command=self.updatetext)button.pack()self.wintext()def wintext(self):lable = tk.Label(self,textvariable=self.advertise)lable.pack(side='bottom')def setcontent(self):self.advertise.set(self.content)def updatetext(self):self.content = self.textentry.get()self.start()def dataupdate(self):self.content = self.content[1:]+self.content[0]# print(self.content)self.after(500,self.start)def start(self):self.setcontent()self.dataupdate()self.pack(side='bottom')if __name__ == '__main__':root = tk.Tk() #創建窗口對象的背景色root.title('廣告牌 演示')root.geometry('300x200')frame1 = tk.Frame(root)frame1.pack(side = 'top')win_ad = Show_ad(root)root.mainloop()?
總結
以上是生活随笔為你收集整理的Python:tkinter简易广告牌的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 会员测试环境治理之路
- 下一篇: 关于销售提成的问题