Tkinter looks different on different computers

The tkinter window looks very different on different computers (it works at the same resolution!):

windows 8 windows 8

windows 7 windows 7

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

My code is as follows:

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 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() 
+5
source share
2 answers

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

In most cases, this is the desired behavior. You want the button on Windows to look like a Windows button, and you want the button on OSX to look like an OSX button. It also means that you can use different buttons in Windows 7 and Windows 8 - tkinter uses only what the OS provides, and Microsoft tends to customize its widgets with each major revision.

Can you get the exact look on all platforms? It depends. You will probably get almost the same results on Windows 7 and 8 with a bit of work. With Windows and Macintosh, it will be very difficult to get the same look.

Unfortunately, these differences not only lead to different widgets, but can also cause a difference. For example, on different platforms there may be different fonts, different default border widths and default margins and indents. All this contributes to the final layout of the window.

In your particular case, the most obvious difference is that Windows 7 uses a slightly smaller font than Windows 8. This in itself can have a big impact on the layout. It also seems that the McListBox widget has a larger border around it on windows 7 than on Windows 8. I don't know anything about this widget, so it can have different defaults based on the platform.

Most of these problems can be solved using explicit values ​​for borders, additions, fonts, etc. Sometimes this requires a bit of experimentation.

+5
source

Is it possible?

Although this seems like a natural desire, the goal is not possible due to many reasons in Tk / Tcl depending on the window manager services localhost O / S. Here it begins. {MacOS, Linux OS, W * OS} -WM-definitely perform similar tasks, however, not with the same appearance.

The simplest view of quite different results .pack() Geometry Manager displays on the second line only a few trivial Button() -s there

The next hit could be the use of the Tk Themed Widget library, aka ttk

 from Tkinter import * from ttk import * 

With ttk you create GUI files with ttk. <Widgets>, 11 of which already exist in Tkinter: ttk.Button, ttk.Checkbutton, ttk.Entry, ttk.Frame, ttk.Label, ttk.LabelFrame, ttk.Menubutton, ttk.PanedWindow, ttk.Radtbutton. Scale and ttk.Scrollbar added some new widget classes - Combobox, Notebook, Progressbar, Separator, Sizegrip and Treeview - all of which are comfortably "subclassed" from the widget.

The key issue is the topic.

look-and-feel , as well as style code (+ ttk style-configuration effort), are trying to help improve the look of the cross-platform interface.

While it brings you closer , it’s not easy to have an identical appearance on both the X11 terminal and W7.

+2
source

Source: https://habr.com/ru/post/1200552/


All Articles