Tkinter looks different on different computers

2024/10/12 16:22:45

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

windows 8 windows 8

windows 7 windows 7

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

My code looks like this:

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 = Falsefor 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()
Answer

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.

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.

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.

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.

https://en.xdnf.cn/q/69630.html

Related Q&A

Sort when values are None or empty strings python

I have a list with dictionaries in which I sort them on different values. Im doing it with these lines of code:def orderBy(self, col, dir, objlist):if dir == asc:sorted_objects = sorted(objlist, key=la…

How to tell if you have multiple Djangos installed

In the process of trying to install django, I had a series of failures. I followed many different tutorials online and ended up trying to install it several times. I think I may have installed it twice…

Python Numerical Integration for Volume of Region

For a program, I need an algorithm to very quickly compute the volume of a solid. This shape is specified by a function that, given a point P(x,y,z), returns 1 if P is a point of the solid and 0 if P i…

invalid literal for int() with base 10: on Python-Django

i am learning django from official django tutorial. and i am getting this error when vote something from form. this caused from - probably - vote function under views.py here is my views.py / vote func…

How to use HTTP method DELETE on Google App Engine?

I can use this verb in the Python Windows SDK. But not in production. Why? What am I doing wrong?The error message includes (only seen via firebug or fiddler)Malformed requestor something like thatMy…

Python heapq : How do I sort the heap using nth element of the list of lists?

So I have lists of lists getting added to the heap; eg:n = [[1, 5, 93],[2, 6, 44],[4, 7, 45],[6, 3, 12]]heapq.heapify(n)print(n)This compares and sorts according to the lists first element.My question …

How strings are stored in python memory model

I am from c background and a beginner in python. I want to know how strings are actually stored in memory in case of python.I did something likes="foo"id(s)=140542718184424id(s[0])= 140542719…

The _imaging C module is not installed (on windows)

Im trying to generate some pdf with django/PIL/Imaging and everything is good until I attempt to put some images into the pdf:Exception Type: ImportError Exception Value: The _imaging C module is n…

HOW TO use fabric use with dtach,screen,is there some example

i have googled a lot,and in fabric faq also said use screen dtach with it ,but didnt find how to implement it? bellow is my wrong code,the sh will not execute as excepted it is a nohup taskdef dispatc…

Developing for the HDMI port on Linux

How would it be possible to exclusively drive the HDMI output from an application, without allowing the OS to automatically configure it for display output?For example, using the standard DVI/VGA as t…