Bottom Page

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.
Quote
#2
What sort of problems are you having?
Paste the code that is giving problems in code tags and any errors in error tags.
Quote
#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
Yoriz wrote Oct-10-2019, 10:48 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#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()
Quote
#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
Quote
#6
did you indent screen.mainloop() to be part of main_screen()?
Quote
#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
Quote
#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!
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)