如何在标签中的 tkinter 上制作字幕?

编程入门 行业动态 更新时间:2024-10-17 22:23:18
本文介绍了如何在标签中的 tkinter 上制作字幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有这个源代码:

from Tkinter import *
import tkMessageBox
import time
class Window(Tk):
    def __init__(self,parent):
        Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()


    def initialize(self):
        self.geometry('450x250+0+0')
        self.configure(background="#379DDB")
        self.title('Konversi Bilangan')
        **self.label = Label(self, text='Konversi Dari',font=('times',24,'italic'),bg="#379DDB")**
        self.label.pack()
        self.tombol=Button(self, text='Biner',font=(18),borderwidth='3px',width=10,command=self.OnButtonClick1,bg="#69ABD3")
        self.tombol.pack(side=TOP)
        self.tombol2=Button(self, text='Desimal',font=(18),borderwidth='3px' ,width=10, command=self.OnButtonClick2,bg="#69ABD3")
        self.tombol2.pack(side=TOP)
        self.tombol3=Button(self, text='Oktal',font=(18),borderwidth='3px' ,width=10,command=self.OnButtonClick3,bg="#69ABD3")
        self.tombol3.pack()
        self.tombol4=Button(self, text='Hexa',font=(18),borderwidth='3px' ,width=10,command=self.OnButtonClick4,bg="#69ABD3")
        self.tombol4.pack()
        self.tombol5=Button(self,text='Quit',font=(18),borderwidth='3px' ,width=10, fg='red', command= self.quit,bg="#69ABD3")
        self.tombol5.pack()

如何从我的粗体中制作选框?如果不可能在 tkinter 中如何制作像 vb 这样的字幕?

How to make marquee from that I bold? If it is not possible how to make marquee like vb in tkinter?

推荐答案

这将很难集成,因为 tkinter 不会玩得很好"无限循环.

This is going to be hard to integrate because tkinter doesn't "play nice" with infinite loops.

下面的程序 在此处的帮助下编写 创建了一个选取框,这只是证明可以做到的一个示例,并且是一种糟糕的方法.

The below program written with assistance from here creates a marquee, this is simply an example to prove this can be done and is a poor way of doing this.

from tkinter import *

root = Tk()

text="Lorem Ipsum"

text = (' '*20) + text + (' '*20)

marquee = Text(root, height=1, width=20)
marquee.pack()

i = 0

def command(x, i):
    marquee.insert("1.1", x)
    if i == len(text):
        i = 0
    else:
        i = i+1
    root.after(100, lambda:command(text[i:i+20], i))

button = Button(root, text="Start", command=lambda: command(text[i:i+20], i))
button.pack()

root.mainloop()

这也使用了 Text 小部件而不是 Label 小部件,主要是因为这样做更简单.

This also uses the Text widget instead of the Label widget, mostly because it's simpler to do this way.

要在程序启动时启动它,只需将其调整为以下内容:

To start it on program launch, simply adjust it to the below:

from tkinter import *

root = Tk()

text="Lorem Ipsum"

text = (' '*20) + text + (' '*20)

marquee = Text(root, height=1, width=20)
marquee.pack()

i = 0

def command(x, i):
    marquee.insert("1.1", x)
    if i == len(text):
        i = 0
    else:
        i = i+1
    root.after(100, lambda:command(text[i:i+20], i))

command(text[i:i+20], i)

root.mainloop()

这篇关于如何在标签中的 tkinter 上制作字幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:34:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字幕   标签   如何在   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!