0

我在 GUI 中设置了很多项目,比如表格、标签、按钮。问题是当我在 Windows 10 中使用这个 GUI 时,一切都不像它在 Linux 中出现的那样出现。(例如,只有一半的表是可见的)我不知道要使用什么才能让它工作并且一切都可以出现/ 适用于两个操作系统。我可以使用包而不是地方,但是当您有很多物品时,这非常困难。我尝试对项目进行分类并使用 5-6 帧,但帧不起作用,因为我有背景图像。

from tkinter import *
from tkinter import ttk
from tkinter.font import BOLD
from tkinter import messagebox
from PIL import ImageTk



class MyApp():
    def __init__(self,window):
        self.window = window
        self.w, self.h = self.window.winfo_screenwidth(), self.window.winfo_screenheight()
        #self.window.geometry("%dx%d" % (self.w, self.h))
        self.window.attributes("-zoomed",True) ## for WINDOWS self.window.attributes("-fullscreen", self.fullScreenState)
        bg = ImageTk.PhotoImage(file = "a.jpg")
        # Show image using label
        label1 = Label(self.window,image=bg)
        label1.place(x=0,y=0,width= self.w, height=self.h)
        self.widgets()
        # Infinite loop can be terminated by keyboard or mouse interrupt
        self.window.protocol("WM_DELETE_WINDOW",self.exit)
  
        self.window.mainloop()
        

    def exit(self):
        if messagebox.askokcancel("Quit", "Do you want to quit?"):
            self.window.destroy()


            
    def widgets(self):
        
        #style.theme_use('pastel')

        self.tree = ttk.Treeview(self.window, columns=("columns1","columns2","columns3","columns4" ), show="tree",
        selectmode="extended")
        self.tree.place(x=995,y=130,width=863,height=602)
        table_style = ttk.Style()
        table_style.configure('Treeview', rowheight=60,background = "white",fieldbackground = "white",font=('Calibri', 15))
        table_style.configure("Treeview.Heading", foreground='#00337f',background ="#3D98DD")
        self.tree.column("#0", minwidth=0, width=180, stretch=NO)
        self.tree.column("#1", minwidth=0, width=180, stretch=NO)
        self.tree.column("#2", minwidth=0, width=180, stretch=NO)
        self.tree.column("#3", minwidth=0, width=180, stretch=NO)
        self.table_lable = Label(self.window)
        self.table_lable.place(x=996,  y=30)
        for row in range(11):
            self.tree.insert("", END, values="",text="ROW %d"%row)
            self.tree.insert("", "end", values="", tag='gray',text="")
        self.tree.tag_configure('gray', background='#cccccc')

        self.panel = Label(self.window,borderwidth=10, relief="groove")
        self.panel.place(x=20, y=130,width=560,height=500)

        self.panel2 = Label(self.window,borderwidth=10, relief="groove")
        self.panel2.place(x=640, y=130,width=300,height=500)

        self.max_prog_nr = 0
        self.style = ttk.Style(self.window)
        self.style.layout('text.Horizontal.TProgressbar',
                    [('Horizontal.Progressbar.trough',
                    {'children': [('Horizontal.Progressbar.pbar',
                                    {'side': 'left', 'sticky': 'ns'})],
                        'sticky': 'nswe'}),
                    ('Horizontal.Progressbar.label', {'sticky': ''})])
                    # , lightcolor=None, bordercolo=None, darkcolor=None
        self.style.configure('text.Horizontal.TProgressbar', text='0 %')
        self.progress_bar = ttk.Progressbar(self.window, style='text.Horizontal.TProgressbar', length=560,
                                    maximum=self.max_prog_nr, value=0)
        self.progress_bar.place(x=20,  y=60)
        prog_bar_label = Label(self.window)
        prog_bar_label.place(x=20, y=30)
        self.prog_num = 1

window= Tk()
start= MyApp(window)
window.mainloop()

这是来自 Windows 和 Linux 的屏幕截图。

Linux

视窗 10

4

0 回答 0