gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:44:36 24 4
gpt4 key购买 nike

我有这个源代码:

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 那样制作选框?

最佳答案

在 tkinter 中制作动画的模式是使用 after 一次安排一帧动画。它看起来像这样,其中 fps 定义为每秒所需的帧数,widget 是 tkinter 小部件:

def animate():
<draw one frame of animation>
widget.after(int(1000/fps), animate)

对于选取框,最简单的解决方案之一是使用 Canvas ,因为它有一个方便的 move 方法,可用于从右向左移动文本。

这是一个例子:

import tkinter as tk

class Marquee(tk.Canvas):
def __init__(self, parent, text, margin=2, borderwidth=1, relief='flat', fps=30):
super().__init__(parent, borderwidth=borderwidth, relief=relief)

self.fps = fps

# start by drawing the text off screen, then asking the canvas
# how much space we need. Use that to compute the initial size
# of the canvas.
text = self.create_text(0, -1000, text=text, anchor="w", tags=("text",))
(x0, y0, x1, y1) = self.bbox("text")
width = (x1 - x0) + (2*margin) + (2*borderwidth)
height = (y1 - y0) + (2*margin) + (2*borderwidth)
self.configure(width=width, height=height)

# start the animation
self.animate()

def animate(self):
(x0, y0, x1, y1) = self.bbox("text")
if x1 < 0 or y0 < 0:
# everything is off the screen; reset the X
# to be just past the right margin
x0 = self.winfo_width()
y0 = int(self.winfo_height()/2)
self.coords("text", x0, y0)
else:
self.move("text", -1, 0)

# do again in a few milliseconds
self.after_id = self.after(int(1000/self.fps), self.animate)

root = tk.Tk()
marquee = Marquee(root, text="Hello, world", borderwidth=1, relief="sunken")
marquee.pack(side="top", fill="x", pady=20)

root.mainloop()

关于python - 如何在标签中的 tkinter 上制作字幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com