Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter
#1
Hello i am a recently new programmer. An A-Level student who is having problems with using tkinter. Im using Python 3.74 which already has tkinter built in . But not sure how to use it that well. Im trying to do beginner projects like making a GUI with a login and register system, yes i know im a noob. just looking for any advice or tips.
Reply
#2
What sort of problems are you having?
Paste the code that is giving problems in code tags and any errors in error tags.
Reply
#3
(Oct-10-2019, 08:11 PM)Yoriz Wrote: What sort of problems are you having?
Paste the code that is giving problems in code tags and any errors in error tags.

from tkinter import *

def main_screen():
    screen = Tk()
    screen.geometry("300x250")
    screen.title("Notes 1.0")
    Label(text = "Notes 1.0", bg = "grey", font = ("Arial", 13)).pack()
    Button(text = "Login").pack()
    Label(text = "").pack()
    Button(text = "Register").pack()

mainscreen.mainloop()


main_screen()

(Oct-10-2019, 08:11 PM)Yoriz Wrote: What sort of problems are you having? Paste the code that is giving problems in code tags and any errors in error tags.


The error code is;
Error:
File "/Users/masonarbon/Desktop/Mason Arbon Python/School work/GUI Login.py", line 12, in <module> mainscreen.mainloop() NameError: name 'mainscreen' is not defined
Reply
#4
Change
def main_screen():
    screen = Tk()
    ...
    Button(text = "Register").pack()
 
mainscreen.mainloop()
to
def main_screen():
    screen = Tk()
    ...
    Button(text = "Register").pack()
 
    screen.mainloop()
Reply
#5
(Oct-10-2019, 10:52 PM)Yoriz Wrote: Change
def main_screen(): screen = Tk() ... Button(text = "Register").pack() mainscreen.mainloop()
to
def main_screen(): screen = Tk() ... Button(text = "Register").pack() screen.mainloop()
It says that the name 'screen' is not defined
Reply
#6
did you indent screen.mainloop() to be part of main_screen()?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
from tkinter import *
 
def main_screen():    
    screen.geometry("300x250")
    screen.title("Notes 1.0")
    Label(text = "Notes 1.0", bg = "grey", font = ("Arial", 13)).pack()
    Button(text = "Login").pack()
    Label(text = "").pack()
    Button(text = "Register").pack()
 
if __name__ == '__main__':
    screen= Tk()
    main_screen()
    screen.mainloop()
or
from tkinter import *
 
def main_screen():
    screen= Tk()
    screen.geometry("300x250")
    screen.title("Notes 1.0")
    Label(text = "Notes 1.0", bg = "grey", font = ("Arial", 13)).pack()
    Button(text = "Login").pack()
    Label(text = "").pack()
    Button(text = "Register").pack()
    screen.mainloop()
 
if __name__ == '__main__':    
    main_screen()
are the same output also create a frame to contain the widgets
Reply
#8
(Oct-11-2019, 03:12 PM)joe_momma Wrote:
 from tkinter import * def main_screen(): screen.geometry("300x250") screen.title("Notes 1.0") Label(text = "Notes 1.0", bg = "grey", font = ("Arial", 13)).pack() Button(text = "Login").pack() Label(text = "").pack() Button(text = "Register").pack() if __name__ == '__main__': screen= Tk() main_screen() screen.mainloop() 
or
 from tkinter import * def main_screen(): screen= Tk() screen.geometry("300x250") screen.title("Notes 1.0") Label(text = "Notes 1.0", bg = "grey", font = ("Arial", 13)).pack() Button(text = "Login").pack() Label(text = "").pack() Button(text = "Register").pack() screen.mainloop() if __name__ == '__main__': main_screen() 
are the same output also create a frame to contain the widgets
Thanks al, i now have it working!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020