How do I write Python code that enters a file and outputs its 'type-size' properties?

How do I write Python code that enters a file’pdf,word, png…’ and outputs its ‘type-size’ properties ? How do I write Python code that enters a file and outputs its ‘type-size’ properties >Solution : For the type check this out: https://pypi.org/project/filetype/ For the size you can just use os.path.getsize()

Python/Tkinter: fine points about super init and self

Following is very simple code to create a frame and label as a class: class FrameWithLabel(tk.Frame): def __init__(self, parent): super().__init__(self, parent) self.label = tk.Label(self) I have two questions: In an earlier post, it was explained to me why the super init was required (in this case, referring to the tk.Frame), and that without the super… Read More Python/Tkinter: fine points about super init and self

Issues with tKinter

This is my first time ever writing here. Also my first time actually coding. I’ve made a code but have issues running it due to tKinter not seeming to exist, even though I’ve specifically installed python from the official webpage and also ticked the tcl/tk options. When trying to launch my code i get this… Read More Issues with tKinter

How to pass the input of a textbox to a variable in python tkinter?

I am trying to make a variable that stores the input inside a textbox on the press of the button. As an example: when button1 pressed: a = textbox1.input My current code so far is: import tkinter as tk window = tk.Tk() window.title("A simple window") window.geometry("150×150") def save_textbox_input(): # Code goes here button = tk.Button(text="Click… Read More How to pass the input of a textbox to a variable in python tkinter?

How do I compress repeating tkinter code into a loop so it displays rectangles without having to write out each individual rectangle's coordinates?

I have some code that repeats that I would like to compress into a loop somehow. The code is meant to show a series of rectangles that change color when your mouse hovers over them, and because I have numerous rectangles, all of the code repeating is the same except for 2 coordinates for the… Read More How do I compress repeating tkinter code into a loop so it displays rectangles without having to write out each individual rectangle's coordinates?

function passed in tkinter after() method can't give return value

I’m trying to replace sleep() with after() but I need to create a function which will give me a return value that I can store and I can’t figure out how. Let’s take this code : import tkinter root = tkinter.Tk() def test(i): o=i*2 return o print(root.after(5000,test,6)) root.mainloop() This results in this output: after#2914 which… Read More function passed in tkinter after() method can't give return value

How to limit the character in Entry

I need to limit the entry to a maximum of 5 digits. def validate(S): try: float(S) return True except ValueError: messagebox.showerror(message="Datos erroneos, únicamente números.", title="ERROR") return False e1 = tk.Entry(master, validate="key", validatecommand=(master.register(validate), ‘%S’)) I have this method to receive and validate that it’s just numbers at the entry, but i would like to know how… Read More How to limit the character in Entry

How do I update a label with information that changes based on a button click

import tkinter top = tkinter.Tk() class Person: def __init__ (self): self.health = 100 def sword(self): self.health = self.health – 10 print(self.health) n = Person() sh = tkinter.Label(top, text=str(n.health)).place(x = .5, y = .5) button = tkinter.Button(top, text="sword", command=n.sword) button.place(relx=0.015, rely=0.5, relheight=0.3, relwidth=0.3) top.mainloop() I am trying to make a mini app that whenever I click… Read More How do I update a label with information that changes based on a button click