New answers tagged

1

This is my revision using the advice found here. The flashcards themselves are not as easily displayed yet, but I'm going to figure that out later. # Begin coding from tkinter import Tk, Menu, Button, Label, Frame card_num = 0 def main(): # Use this function to create root window background_color = 'navy' root = Tk() root.title('Flashyr') ...


12

First off, it's fantastic that you're grouping your widgets together when you create them, and then grouping your calls to grid together. Most people who are starting to learn tkinter don't do that. The way you've done it makes the code much easier to understand than if you mixed it all together. Don't use wildcard imports Wildcard imports are discouraged ...


5

Namespace pollution It's usually a bad idea to do this: from tkinter import * This forces every bell and whistle from tkinter to be imported. Instead, either import tkinter as tk, or from tkinter import Tk, ... if you aren't importing a lot of symbols. Order of operations The parens here: x = (screen_width/2) - (width/2) y = (screen_height/2) - (...


1

Don't use wildcard imports. Import tkinter with import tkinter as tk, and then prefix all of your calls to tkinter classes with tk.. For example: import tkinter as tk window = tk.Tk() ... title = tk.Label(window, text="Basic Converter", font="Calibri 16") filemenu = tk.Menu(window) ... PEP8 is a set of guidelines that most python programmers follow, and ...


0

Let's look at this code: for i in self.cpu_moves: root.after(200, animate(self.btns[i])) First, you're not using after correctly. You're doing the equivalent of this: for i in self.cpu_moves: result = animate(self.btns[i]) root.after(200, result) You might as well not call root.after at all, since result will be None. If you need to pass ...


3

Type hints """ Attributes: name(str): Activity Name iid(str): Activity ID, uniquely identifies the activity start(str): Start Time end(str): End Time parent() """ It's nice that you've documented these types, but it would be better to tell Python (or at least your IDE) about them: def __init__(self, name: str, ...


1

Don't use wildcard imports Instead of from tkinter import *, use import tkinter as tk. Then, wherever you reference a tkinter class or value, prefix it with tk. (eg: tk.Label, tk.Button`, etc). This makes your code easier to understand, and helps keep the number of objects in the global namespace low. Plus, it keeps it consistent with PEP8 guidelines. ...


Top 50 recent answers are included