Tkinter 在不同的计算机上看起来不同 [英] Tkinter looks different on different computers

查看:63
本文介绍了Tkinter 在不同的计算机上看起来不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 tkinter 窗口在不同的计算机上看起来非常不同(以相同的分辨率运行!):

My tkinter window looks very different on different computers (running on the same resolution!):

视窗 8

Windows 7

我希望它看起来像第一个.有什么想法吗?

I want it to look like it does in the first one. Any ideas?

我的代码如下所示:

class Application():
    def __init__(self):
        self.app = Tk()
        self.app.wm_iconbitmap('.\data\spider.ico')
        self.app.wm_title("Spider Crawler")
        self.app.minsize(width=914, height=331)
        self.app.maxsize(width=914, height=331)

        mainmainleft = Frame(self.app)
        bottom = Frame(self.app)

        mainleft = Frame(mainmainleft)
        itemoptions = Frame(bottom)
        self.graph = multilist.McListBox(bottom)

        startn = Frame(mainleft)
        options = Frame(mainleft)
        hourcredits = Frame(mainleft)

        hoursoption = Frame(hourcredits)
        credits = Frame(hourcredits)

        allbuttons = Frame(mainleft)

        fstart = Frame(startn)

        bp = Frame(allbuttons)
        buttons = Frame(allbuttons)

        self.SchemaUpdate = BooleanVar()
        self.reset = BooleanVar()
        self.genuine = BooleanVar()
        self.buds = BooleanVar()
        self.bills = BooleanVar()
        self.unusual = BooleanVar()
        self.maxs = BooleanVar()
        self.bmoc = BooleanVar()
        self.salvage = BooleanVar()
        self.traded = BooleanVar()
        self.entryid = StringVar()

        self.clicked = False

        for i in [self.reset, self.buds, self.unusual, self.maxs, self.salvage]:
            i.set(True)

        self.b = Button(fstart, text="START", command=self.start)
        c = Button(buttons, text="Steam", command=self.steam).pack(side=LEFT, padx=(0,7))
        d = Button(buttons, text="GotoBP", command=self.backpack).pack(side=LEFT)
        self.b.pack(side=LEFT)

        buttons.pack()
        self.var = StringVar(self.app)
        self.var.set("backpack.tf/profiles/")

        option = OptionMenu(bp, self.var, "backpack.tf/profiles/", "tf2items.com/profiles/", "tf2b.com/tf2/")
        option.config(width = 18)
        option.pack()
        bp.pack(side = BOTTOM)    

        self.box = Entry(startn, textvariable=self.entryid, fg = "gray")
        self.box.bind("<Button-1>", self.callback)
        self.box.insert(0, "Enter steamid")
        self.box.pack(side = TOP, anchor=N, padx =(5,25), pady = 10)

        Label(credits, text="Created by Akenne", font=("Times New Roman", 8)).pack(anchor = E, pady = (0,25))

        credits.pack(side=TOP, anchor=E)

        Label(hoursoption, text="Max Hours:").pack(side=LEFT, padx = (0,10))

        self.hours=IntVar()
        self.hours.set(250)
        Entry(hoursoption,textvariable=self.hours,width=5).pack(side=LEFT)

        hoursoption.pack(padx= (0,45))

        Checkbutton(options, text = "Reload item schema", variable = self.SchemaUpdate).pack(side=TOP, anchor=W, pady =(0, 3))
        Checkbutton(options, text = "Start with fresh id", variable = self.reset).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Only never traded items", variable = self.traded).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Genuines", variable = self.genuine).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Earbuds", variable = self.buds).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Bill's", variable = self.bills).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Unusuals", variable = self.unusual).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Max's items", variable = self.maxs).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "BMOCs", variable = self.bmoc).pack(side=TOP, anchor=W)
        Checkbutton(itemoptions, text = "Salvaged crates", variable = self.salvage).pack(side=TOP, anchor=W)
        self.lbl = Label(fstart, text="0/0 found")
        self.lbl.pack(side = LEFT, anchor = W, padx = (20,30))

        fstart.pack(side=TOP)

        startn.pack(side=LEFT, anchor = W, padx = (10, 0))
        options.pack(side=LEFT, padx=(0,30), pady = (5,0))
        allbuttons.pack(side=LEFT, pady=(10,0), padx = (40,0))
        hourcredits.pack(side=LEFT, padx = (95,0), anchor = E)

        mainleft.pack(side = TOP, anchor = W)
        self.graph.container.pack(side = LEFT, anchor = W, pady = 10)
        itemoptions.pack(side=LEFT, anchor = E, padx=7)

        mainmainleft.pack(side = TOP, fill = X)
        bottom.pack(padx =10)
        self.app.mainloop()

推荐答案

是的,tkinter 应用程序在不同平台上看起来会有所不同.这是设计使然.如果可能,Tkinter 将使用本机小部件——操作系统提供的小部件.这意味着 Tkinter 无法最终控制 GUI 的各个方面.

Yes, tkinter applications will look different on different platforms. This is by design. When possible, Tkinter will use native widgets -- widgets provided by the OS. This means that Tkinter does not have ultimate control over every aspect of the GUI.

在大多数情况下,这是理想的行为.您希望 Windows 上的按钮看起来像 Windows 按钮,并且希望 OSX 上的按钮看起来像 OSX 按钮.这也意味着您可能会在 Windows 7 和 Windows 8 上获得不同的按钮——tkinter 只是使用操作系统提供的任何东西,而微软倾向于在每次重大修订时调整其小部件.

Under most circumstances this is the desired behavior. You want a button on Windows to look like a Windows button, and you want a button on OSX to look like an OSX button. This also means that you may get different buttons on Windows 7 vs Windows 8 -- tkinter is just using whatever the OS gives it, and Microsoft tends to tweak its widgets with every major revision.

您能否在所有平台上获得完全相同的外观?那要看.只需少量工作,您就可以在 Windows 7 和 8 上获得几乎相同的结果.在 Windows 和 Macintosh 之间获得相同的外观将是非常困难的.

Can you get the exact same look on all platforms? That depends. You can probably get nearly identical results on Windows 7 and 8 with a small amount of work. It will be very difficult to get the same look between Windows and Macintosh.

不幸的是,这些差异不仅会导致小部件外观不同,还会导致布局差异.例如,不同的平台可能有不同的字体、不同的默认边框宽度以及默认的边距和内边距.所有这些都有助于窗口的最终布局.

Unfortunately, these differences not only result in different looking widgets, but it can cause layout differences as well. For example, different platforms may have different fonts, different default border widths, and default margins and padding. All of this contributes to the final layout of a window.

在您的特定情况下,最明显的区别是 Windows 7 使用的字体比 Windows 8 略小.仅此一项就会对布局产生很大影响.看起来 McListBox 小部件在 Windows 7 上的边框比在 Windows 8 上更大.我对该小部件一无所知,因此它可能具有基于平台的不同默认值.

In your specific case, the most obvious difference is that Windows 7 is using a slightly smaller font than Windows 8. That alone can have a big effect on layout. It also appears that the McListBox widget has a larger border around it on windows 7 than on windows 8. I don't know anything about that widget, so it could have different defaults based on the platform.

这些问题中的大多数都可以通过对边框、填充、字体等使用显式值来解决.有时需要一些实验.

Most of these problems can be resolved by using explicit values for borders, padding, fonts, etc. Sometimes it takes a little experimentation.

这篇关于Tkinter 在不同的计算机上看起来不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆