Handling cross-platform differences

Even though Tkinter is a cross-platform module, you might come across occasions when code written for one operating system might not work as expected on other operating systems. We already saw one such example in the case of getting command-line results in the previous Redirecting the command-line output to Tkinter. In such cases, you can overcome these cross-platform discrepancies by first identifying the operating system on which the program is being run and then using a conditional statement to run different lines of code for different operating systems.

Here's a brief snippet that demonstrates this concept:

 from platform import uname operating_system = uname()[0] if ( operating_system == "Linux" ): ...

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.