Label1 = tkinter.Label(dashboard_window, text="Dashboard")ī1 = tkinter.Button(dashboard_window, text="New", command=lambda: new(dashboard_window)) id(row=0,column=0,columnspan=3,pady=10,padx=10, sticky="nsw")ī1 = tkinter.Button(new_window, text="Change It", command=lambda: showdashboard(new_window))ī1.grid(row=4,column=1,padx=20,pady=10,sticky="nwse")ī2 = tkinter.Button(new_window, text="Quit", command=lambda: quit())ī2.grid(row=5,column=1,padx=20,pady=10,sticky="nwse")ĭashboard_window.title("My App - Dashboard") Label1 = tkinter.Label(new_window, text="NEW") Is there any way to access them by their names? In tkinter I have found the winfo_children() to access child elements. #Add any root titles, geometry or any other configurations hereĪpp = Window(root) #Instead of Window, replace it with your class nameĪll these features, you can include to make your code neater.Is there any way in Python/tkinter to access child elements referring by their variable names, but from an other function?įor example in VBA, it is possible to directly refer to an element of an other window by its name.įor example if I have two windows, UserForm1 and UserForm2 I can change the text value of Label1 of UserForm2 by clicking a button on UserForm1. The class makes your code neat and tidy while the _init_ and super() are needed for whenever you make a function.Īlso, you can use the _name_ = "_main_" if condition to stop the code from running when importing it to another script. Inside the _init_ function you write: super()._init_(master, **kwargs) Inside it you need to write the _init_ function: def _init_(self, master, **kwargs): #Feel free to add any extra parameters You can do this like so: class Name(tk.Frame): It will certainly clean up the attributes, and you will not having them together with all of the built in attributesĪlso, get all of your widgets into a class. Also, if you use from tkinter import * you can use import tkinter as tk instead as it groups all attributes into tk. This means you can write tk.widget and not having to write out every widget you use. Instead of from tkinter import Tk use import tkinter as tk. It will also get rid of the bar at the top, so you will have to use alt f4 to exit out of the window.Īlso, these options are optional but will certainly make your code more clear and efficient by getting rid of possible errors which may occur when doing certain tasks with the code. You can use window.overrideredirect(True) to get rid of the task bar. Window.geometry("%sx%s" %(screenWidth, screenHeight) This is how to do it: windowWidth = window.winfo_screenwidth Instead of using monitorInfo you can use winfo_screedwidth() and winfo_screenheight(). To everyone who commented and offered solutions for me, thank you! I really appreciate you taking the time to do so. That question didn't really put the pieces together in a newbie-friendly way, nor did it have any usable sample code, so hopefully this will be of use to someone else in the future.) (The breakthrough was examining all the properties mentioned in the suspected duplicate question (and it's comments and replies) here: tkinter window get x, y, geometry/coordinates without top of window Window.geometry(" 0 0".format(windowWidth,windowHeight)) #Set the new window to upper left corner and height
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |