如果我手动放大窗口,我会看到文字,所以文字就在那里! (在标签上)但如果没有放大我看不到的窗口,我只看到一块标签
我该如何解决?我需要调整大小吗?
我尝试过更改字体大小,标签大小以及其他一些内容,我甚至无法解决问题。
这是代码:
from Tkinter import *
import ttk
import time
import threading
def start():
start_stop.config(text="QUIT", command=stop, image=photo2)
thread = threading.Thread(target=progBar, args=())
thread.daemon = True
thread.start()
def progBar():
for i in xrange(300):
if i < 50:
lbl1.config(height=0, width=4, font=('times', 400, 'bold'),
text="AAAA!!")
lbl1.config(fg='black')
if i % 5:
lbl1.config(bg='white')
else:
lbl1.config(bg='red')
if i == 50:
lbl1.destroy()
if i >= 200:
s = ttk.Style()
s.theme_use('clam')
if i % 5:
s.configure("red.Horizontal.TProgressbar",
foreground='#205F8C', background='#205F8C')
else:
s.configure("red.Horizontal.TProgressbar",
foreground='red', background='red')
pbar_det.config(style="red.Horizontal.TProgressbar")
pbar_det.step(0.33)
master.update()
# Busy-wait
time.sleep(0.1)
master.destroy()
def stop():
master.destroy()
master = Tk()
photo1 = PhotoImage(file="Press1.gif")
photo2 = PhotoImage(file="Press2.gif")
ws = master.winfo_screenwidth() # width of the screen
hs = master.winfo_screenheight() # height of the screen
width = ws
height = 120
x = ws-width # Window's coords
y = hs-height
start_stop = Button(master, text='START', command=start, image=photo1)
start_stop.grid(row=0, column=1, pady=2, padx=2, sticky=E+W+N+S)
pbar_det = ttk.Progressbar(master, orient="horizontal", length=ws-450,
mode="determinate")
pbar_det.grid(row=0, column=0, pady=2, padx=2, sticky=E+W+N+S)
lbl1 = Label(master)
lbl1.grid(row=0, column=1, pady=2, padx=2)
lbl2 = Label(master)
lbl2.grid(row=0, column=1, pady=2, padx=2)
master.geometry('%dx%d+%d+%d' % (width, height, x, y))
master.mainloop()
答案 0 :(得分:0)
尝试将标签内的文本锚定在左侧。
lbl1.config(anchor="nw") # nw = north-west = top left
答案 1 :(得分:0)
我在代码中看到至少四个问题:
master.geometry(...)
时,您正在将窗口小部件的大小强制设置为特定高度。这可以防止窗口增长或缩小以适应内部小部件如果删除对master.geometry()
的调用,窗口将展开以适合文本的高度。或者,你不能使字体如此巨大。