Problem with Python Code
Posted by Relevant_Milk4413@reddit | learnprogramming | View on Reddit | 8 comments
I have a problem with my python code. I am using Tkinter to build a hospital management System. But the text of the buttons is not visible.
I found the tutorial of this management system on youtube, i am trying to rebuild it alone.
I watched the tutorial of him, but i didn't find the mistake i did.
I hope somebody could help me
https://github.com/OmarHashem28/LearnProgramming2.git
Outside_Complaint755@reddit
I don't see any obvious problem, but I'm currently on mobile and can't run it. I will take a look when I have an opportunity
Does anything become visible when you mouse over a button, changing the state to Active? Maybe try adjusting the colors to just black and white while you make adjustments.
As an aside, instead of retyping out the font tuple separately for each button, just make a font object and pass it to the parameter for each. It will make adjustments simpler as you can just change it in one place for all buttons.
Relevant_Milk4413@reddit (OP)
Even when i click or when the mouse is over a button nothing become visible. I tried to adjust the colors into fg='white' and bg='green'.
Outside_Complaint755@reddit
Besides the proposed fix in my other comment, here's a couple of other tips:
1) Instead of repeating the same
font=("times new roman", 12, "bold")for every widget, declare it once as a variable and use that variable. This also makes it easier to apply different fonts to different parts of the UI.2) Because most of your widgets are sharing identical parameters, instead of typing them out for each widget separately, set them into a dictionary and then unpack the dictionary for the keyword arguments using the ** operator. For example, during testing I was able to condense the entire buttons section down to this:
This both saves you screen space, and also means that if you want to change any of those parameters, you only have to change it in one place to apply to all buttons.
Outside_Complaint755@reddit
Ok, I got this figured out. The ultimate underlying problem is with your
width=23,height=16,padx=2,pady=6,parameters. For a button with a text label, width and height are not in pixels, but instead width = characters wide, and height = rows of text. As a result, your buttons are being created much taller than needed (16 rows tall), going below the limits of the ButtonsFrame, and the text is hidden down there.A couple of ways to fix this: 1) Remove the width, height, padx and pady parameters from your buttons. 2a) You can add width back in if you want to set a different width for each button, but remember it is character based, not pixel. 2b) Alternatively, set the column weight for each column to 1, and then set the parameter
sticky="EW"for each call to.grid(). Example:2c) Instead of using grid with sticky and setting column weights, you could use pack and tell it to expand:
Note that you can't mix grid and pack in the same frame, so you have to change all buttons to use pack or all have to use grid.
Middle--Earth@reddit
Could you post a link to the tutorial?
Relevant_Milk4413@reddit (OP)
https://youtu.be/HrWJzzfU9Z0?is=mNFZUqFj4iiCHJJV
It's in (indian)english
Middle--Earth@reddit
You have used this in your code:
btnPresciptionData = Button(Buttonsframe .....
But you have a couple of typos there.
Buttonsframe should be Buttonframe - which is probably the root of your problem as you have used it in all your button object rerences.
But you also have a typo in the handle btnPrescription and btnPrescriptionData - where you have left out the second letter 'r'.
I hope that helps.
Outside_Complaint755@reddit
'Buttonsframe' is correct, because earlier in the routine, it is created as Buttonsframe