i am trying to make a library management system in python using oops and tkinter. here is the code:
from tkinter import *
class library():
def __init__(self):
self.screen=Tk()
self.title='LOGIN'
self.screen.minsize(800,600)
self.screen.maxsize(800,600)
self.screen.title(self.title)
c=Canvas(self.screen,bg='black').place(x=-10,y=0,height=1000,width=1000)
def screen_work(self):
self.screen_login().screen.destroy()
screen=Tk()
screen.title('LIBRARY MANAGEMENT')
#screen.attributes('-fullscreen',True)
def button(self):
Button(self.screen,text='press',bg='red').place(x=400,y=300)
lib=library()
mainloop()
now ,when i run this program a black screen of dimension '800x600; opens up without any errors but does not show any button.
CodePudding user response:
You don’t really need to use a function to add a button, you may just leave the button code near the end after the other functions. If you want to keep the function, I think you forgot to declare the function in order for the button to appear.
CodePudding user response:
As Bryan Oakley and JRiggles rightly stated, the button function is never called, so it wouldn't display
updated code
from tkinter import *
class library():
def __init__(self):
self.screen=Tk()
self.title='LOGIN'
self.screen.minsize(800,600)
self.screen.maxsize(800,600)
self.screen.title(self.title)
c=Canvas(self.screen,bg='black').place(x=-10,y=0,height=1000,width=1000)
def screen_work(self):
self.screen_login().screen.destroy()
screen=Tk()
screen.title('LIBRARY MANAGEMENT')
#screen.attributes('-fullscreen',True)
def button(self):
Button(self.screen,text='press',bg='red').place(x=400,y=300)
lib=library()
lib.button()
mainloop()
here's a great resource to learn tkinter in case you're interested! https://realpython.com/python-gui-tkinter/