Question

- x Lè DRAFT P1.py - C:\Users\Darren Louw\Desktop\DRAFT P1.py (3.8.2)* File Edit Format Run Options Window Help from tkinterQuestion:

I am unable to get a output of my function on my label1 when I click on button 1, please help?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have written the program and made changes just to display the value on label1 when button1 is pressed. Notice the code on line 13, label1.config() is used to refresh the text attribute of the label1. Below is the screenshot of the code to check indentation.

ܠܚܪ 4 7 from tkinter import * 2 HEIGHT = 300 3 WIDTH = 400 root = Tk() 5 6 -def count(): count1=0 8 for i in range(1,1001): 9

Below is the output of the code:

Before the button B1 is pressed:

tk B1

After B1 is pressed:

tk U B1 969 T1PNP

Below is the code to copy:

from tkinter import *
HEIGHT = 300
WIDTH = 400
root = Tk()

def count():
   count1=0
   for i in range(1,1001):
      num = i*i
      if num> 1000:
         count1+=1
   print ("Numbers in range 1 to 1000 that are non perfect squares are:",count1)
   label1.config(text=count1) #CHANGED LINE

canvas = Canvas(root,height=HEIGHT, width =WIDTH)
canvas.pack()

frame=Frame(root,bg='green', bd=5)
frame.place(relx=0.5,rely=0.1, relwidth=0.75, relheight= 0.4, anchor='n')

button1= Button(frame, text='B1', font = 40, command=count)
button1.place(relx=0, relwidth=0.25, relheight= 0.5)

lowerframe = Frame(root, bg='green', bd=10)
lowerframe.place(relx=0.5, rely=0.6, relwidth=0.75, relheight=0.2, anchor='n')

label1=Label(lowerframe,bg='white', font=30)
label1.place(relwidth=0.25, relheight=0.8, relx=0)

root.mainloop()
Add a comment
Know the answer?
Add Answer to:
Question: I am unable to get a output of my function on my label1 when I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • When i run my python code i get the following error... and im not sure how...

    When i run my python code i get the following error... and im not sure how to fix the error, can someone help me? ____________________Hers my Code__________________ import face_recognition import cv2 # Get a reference to your webcam video_capture = cv2.VideoCapture(0) # Load a sample picture of yourself and learn how to recognize it. kyle_image = face_recognition.load_image_file("kyle.jpg") kyle_face_encoding = face_recognition.face_encodings(kyle_image)[0] # Load a second sample picture and learn how to recognize it. ##lauren_image = face_recognition.load_image_file("lauren.jpg") ##lauren_face_encoding = face_recognition.face_encodings(lauren_image)[0] # Load...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT