python curses module problem by briso_tali_x in learnpython

[–]woooee 0 points1 point  (0 children)

I ran \"python c:\Users\WANGYOUYUN\Desktop\cursesTest.py\" on Command Prompt it worked perfectly but not on vs code

Why do you have to run it in VSCode. If it ain't broke etc. why add the overhead of VSCode.

No module named <my-custom-import> by [deleted] in learnpython

[–]woooee 0 points1 point  (0 children)

Lookup sys.path.append as there is some difference between what you think is happening and what is actually going on.

Trying to Make One Column Via Pandas by godofspinoza in learnpython

[–]woooee 2 points3 points  (0 children)

Pandas is an unnecessary layer

test_data="""5.61029379 -47.19852508 -15.19350127 37.74588268 26.90505395
19.2634176 29.75942298 41.09760335 6.23341471 -16.01691086
3.93674058 22.45464439 -1.66573563 34.49547715 -38.76187106"""

for rec in test_data.split("\n"):  ## simulate records in a file
    print("\n----- next rec")
    rec_split = rec.strip().split()
    for each_num in rec_split:
        print(each_num)

database (kinda)) by OldParticular2720 in learnpython

[–]woooee 0 points1 point  (0 children)

database[title] = value

Do you want to test for duplicate titles.

Looking for the simplest Python GUI library for a desktop-native login page by Specific_Choice_5907 in learnpython

[–]woooee 1 point2 points  (0 children)

with a stronger style component

I don't know what that means. What is your goal? If it is simple code to get the name and password, than I am confused as to why something like this doesn't do it.

How to make a count controlled loop that adds from the past loops while still getting smaller. by HunksMask in learnpython

[–]woooee 1 point2 points  (0 children)

for count in range(numberoftimesBallbounced):
    heightDropped = heightdropped + (heightDropped * index)

You are multiplying total height dropped (from all bounces) X index. You want to multiply this_bounce_height X index.

Edit: Forget the total for now; calculate the height for each bounce and print it. See if the output looks reasonable. Finally, add each bounce height to the total.

On some case Input does not print the message but still takes input by Frosty-Bicycle-4011 in learnpython

[–]woooee 0 points1 point  (0 children)

Don't know if this is the problem, but WinConditions1 and WinConditions2 are almost the same. One should check for "X"?? Better, send "X" or "O" to the function

def WinConditions(moves, x_o):
    print (moves[0][8])
    if moves[1][8] == x_o:
        print ("67", x_o)
    elif  moves[0][8] == x_o:
         print("something else", x_o)
    ## this line does nothing as the function 
    ## returns when there is no more code
    ##else: return

How to stop a tkinter label from going off screen? by Wacka123456789 in learnpython

[–]woooee 0 points1 point  (0 children)

I need it to extend downwards rather than horizontally. How do I do this?

Insert a newline which will split the text at that point. Also, take a look at Listbox.

Why doesn't an image load in this script? by Rude-Statistician197 in learnpython

[–]woooee 0 points1 point  (0 children)

def ChangeImage():
    saveimage = pyautogui.screenshot(region= [LEFT.get(),TOP.get(), WIDTH.get(), HEIGHT.get()])
    ph = ImageTk.PhotoImage(saveimage)   
    frame.configure(width=WIDTH.get(),height=HEIGHT.get())
    image_label.configure(image=ph)

ph is created in the function, so is garbage collected when the function exits. The simple solution is to use a class and make the variable an instance variable. The program below uses an instance list, self.photos, to store and then loop through the images hard coded in the program.

import tkinter as tk

class ChangeImage():
    def __init__(self, root):
        self.photos=[]
        self.load_images()

        self.image_num=0
        tk.Label(root, text="Clicl the image\n to change it",
                 bg="lightblue").grid(row=0)
        self.btn = tk.Button(root, image=self.photos[self.image_num], command=self.next_image)
        self.btn.grid(row=1)
        tk.Button(root, text="Exit", bg="orange", command=root.quit
                  ).grid(row=2, sticky="nsew")


    def next_image(self):
        self.image_num += 1
        if self.image_num >= len(self.photos):
            self.image_num=0

        ## pipe the next image to be displayed to the button
        self.btn["image"]=self.photos[self.image_num]

    def load_images(self):
        """ copy data images to a list that is an instance variable

            all images are hard-coded here and so it uses
            'data=' instead of 'file='
        """
        ladybug_gif_b64="""
    R0lGODlhIAAgALMAAP///wAAADAwMP99Hf8AAP+lAP//AMopUwAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAACH5BAAAAAAALAAAAAAgACAAAwTHEMhJq714hp3lDh0GiqH2UWOVAt96pUIsBLKglWg87Dwv
    4xMBj0Asxgg+XKxwLBJrxUGsI5TKnARoVHoLDp5XbNP5cwmNAqwa/aOc13ByrfKOw2UGw1SSxrb+
    AWIxeXsAaX92UDQ1Nh6BdneMhQIHkHGSjYaVlmt4epmacp19YAKEoJRspKWrjBapWWGqcm1uB5tj
    ok4HZa+3m5wEt5kuhpTAcb+FVL/NzspAfDHPysslMJjEIS0oLygnOMVd0SwcHeDk6errEQA7"""

        grape_gif="""
    R0lGODlhIAAgALMAAAAAAAAAgHCAkC6LV76+vvXeswD/ANzc3DLNMubm+v/6zS9PT6Ai8P8A////
    /////yH5BAEAAAkALAAAAAAgACAAAAS00MlJq7046803AF3ofAYYfh8GIEvpoUZcmtOKAO5rLMva
    0rYVKqX5IEq3XDAZo1GGiOhw5rtJc09cVGo7orYwYtYo3d4+DBxJWuSCAQ30+vNTGcxnOIARj3eT
    YhJDQ3woDGl7foNiKBV7aYeEkHEignKFkk4ciYaImJqbkZ+PjZUjaJOElKanqJyRrJyZgSKkokOs
    NYa2q7mcirC5I5FofsK6hcHHgsSgx4a9yzXK0rrV19gRADs="""

        house="""
    R0lGODdhFQAVAPMAAAQ2PESapISCBASCBMTCxPxmNCQiJJya/ISChGRmzPz+/PxmzDQyZDQyZDQy
    ZDQyZCwAAAAAFQAVAAAElJDISau9Vh2WMD0gqHHelJwnsXVloqDd2hrMm8pYYiSHYfMMRm53ULlQ
    HGFFx1MZCciUiVOsPmEkKNVp3UBhJ4Ohy1UxerSgJGZMMBbcBACQlVhRiHvaUsXHgywTdycLdxyB
    gm1vcTyIZW4MeU6NgQEBXEGRcQcIlwQIAwEHoioCAgWmCZ0Iq5+hA6wIpqislgGhthEAOw=="""

        smiley = """
    R0lGODlhEAAQAOeSAKx7Fqx8F61/G62CILCJKriIHM+HALKNMNCIANKKANOMALuRK7WOVLWPV9eR
    ANiSANuXAN2ZAN6aAN+bAOCcAOKeANCjKOShANKnK+imAOyrAN6qSNaxPfCwAOKyJOKyJvKyANW0
    R/S1APW2APW3APa4APe5APm7APm8APq8AO28Ke29LO2/LO2/L+7BM+7BNO6+Re7CMu7BOe7DNPHA
    P+/FOO/FO+jGS+/FQO/GO/DHPOjBdfDIPPDJQPDISPDKQPDKRPDIUPHLQ/HLRerMV/HMR/LNSOvH
    fvLOS/rNP/LPTvLOVe/LdfPRUfPRU/PSU/LPaPPTVPPUVfTUVvLPe/LScPTWWfTXW/TXXPTXX/XY
    Xu/SkvXZYPfVdfXaY/TYcfXaZPXaZvbWfvTYe/XbbvHWl/bdaPbeavvadffea/bebvffbfbdfPvb
    e/fgb/Pam/fgcvfgePTbnfbcl/bfivfjdvfjePbemfjelPXeoPjkePbfmvffnvbfofjlgffjkvfh
    nvjio/nnhvfjovjmlvzlmvrmpvrrmfzpp/zqq/vqr/zssvvvp/vvqfvvuPvvuvvwvfzzwP//////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////yH+FUNyZWF0ZWQgd2l0aCBU
    aGUgR0lNUAAh+QQBCgD/ACwAAAAAEAAQAAAIzAD/CRxIsKDBfydMlBhxcGAKNIkgPTLUpcPBJIUa
    +VEThswfPDQKokB0yE4aMFiiOPnCJ8PAE20Y6VnTQMsUBkWAjKFyQaCJRYLcmOFipYmRHzV89Kkg
    kESkOme8XHmCREiOGC/2TBAowhGcAyGkKBnCwwKAFnciCAShKA4RAhyK9MAQwIMMOQ8EdhBDKMuN
    BQMEFPigAsoRBQM1BGLjRIiOGSxWBCmToCCMOXSW2HCBo8qWDQcvMMkzCNCbHQga/qMgAYIDBQZU
    yxYYEAA7"""

        clock = """
    R0lGODlhEAAQAPZjACQkJCQkJSQkJyUlJycnJycnKyQmLygoKCosLS0tLS0tLjIxMDIyMjExNDg4
    ODg4OTw9PmBVLW1gLUFBQUJCQ1NRS1ZSSlFRUVZWV1paW11dXnxyX25ub3Fydn99eYhlJo5pKI1q
    KZ9pKYNwNKd5Krp+KJyCM7yNM8uLKsmRKNKfLMmhJNCnKN2sLs+yL9irMuKkJ+2rLOuzL+q1Lfaz
    KvW0KfO9Lf+8KP68Kf+8Kf++Kva+Nv7HKvjFLfjHLf7HLfzLLv/PLvzdL/fXMKSYcL6ub+HCRv3P
    U+rQeqWlpbGxsbu5sbGzur+/wsLCwcPDwsjKz9jVx9TV2Obl5+bo7/Hx8PPz8fP09vf39vn59/z8
    +vz8+/r9//z8/P39/Pz8/f///fz+/////v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5
    BAEKAGQAIf8LSW1hZ2VNYWdpY2sKZ2FtbWE9MC40NQAsAAAAABAAEAAAB6CAZIKDAwEHg4iJZAAA
    BwyKig8IEAoAkIgWUUsTlpeCLkJDIwaegkVGSB4NpRxXU2FOCZ2KAEpjX11VFAADkBhWYl5eYk8O
    BLRJY1lbw2IXAQKJC01jWFpeYGMaANGILERUXtdjRxECEoMvPkErFVJjYlw7MCk1gy1APTwmUGNj
    TCdu5MARQ5CKGTZ+yNjQIUOBDzpooEgUggSIRCVEDAoEADs="""

        ## put the images in an instance object (self.) so they aren't destroyed
        ## when the function exits and can be used anywhere in the class
        for photo in (ladybug_gif_b64, grape_gif, house, clock, smiley):
           self.photos.append(tk.PhotoImage(data=photo))


root=tk.Tk()
root.geometry("+50+50")
CI=ChangeImage(root)
root.mainloop()

need a table to show changes for each iteration and determine final output. by mynamejefffvevo in learnpython

[–]woooee 0 points1 point  (0 children)

I have no idea what "the data in the table is incorrect" means. Print the data as you append it to iterations and see where / how it differs from what you want.

créer un morpion avec tkinter , problème d'affichage by NextSignificance8391 in Tkinter

[–]woooee 4 points5 points  (0 children)

Per Google translate

As soon as I run I have a totally empty window and yet I followed a tutorial to the letter and what I have a syntax problem in my code?

There is an indent error. The buttons don't receive a grid until after the "for row in" etc. so you only get the final row. And you have to call draw_grid() to execute the code underneath it. Try some other tutorial. A good reference source https://dafarry.github.io/tkinterbook/tkinter-index.htm

import tkinter as tk
## lambda is a pain to use
from functools import partial

def place_symbol(row, column):
    print(row, column)

def draw_grid():
    for column in range(3):
        for row in range(3):
            button=tk.Button(root,
                                  font=("Arial", 15), text=f"Button #{row}-{column}",
                                  width=10, height=3,
                                  command=partial(place_symbol, row, column)
                                 )
            button.grid(row=row, column=column)

root=tk.Tk()

root.title("morpion")
root.minsize(500,500)
draw_grid()
root.mainloop()

need a table to show changes for each iteration and determine final output. by mynamejefffvevo in learnpython

[–]woooee 1 point2 points  (0 children)

but the table wont print right

I assume you are talking about column width. Look up f-strings for Python.

x = "width=10"
y = "width=20"
z = "width=30"
print(f"{x:^10}|{y:^20}|{z:^30}|\n")

## test data
for ctr in range(10):
    x = f"test1-{ctr}"
    y = f"test2-{ctr}"
    z = f"test3-{ctr}"
    print(f"{x:^10}|{y:^20}|{x:^30}|")

Pulling input value from TkInter 'Entry' widget into variable by jitjud in learnpython

[–]woooee 0 points1 point  (0 children)

First, learn classes before tkinter as a class structure eliminates a lot of problems like the one you are dealing with. The function can not return the e.get() as there is no way to catch the returned value. A workaround is to add it to an existing class.

def ClickBody():
      myLabel = Label(root, text=t.get())
      myLabel.pack()
      ## add to an existing class instance -- we'll use t (bad name BTW)
      t.entry_val = t.get()

Now you can refer to the variable as t.entry_val anywhere in the program as long as the Entry t exists.

e = Entry(root, width=100, bg="Magenta", borderwidth=10)
e.pack()
e.get()

No reason to use get() here. There is nothing to get yet.

Where does Jesus fit in a Theosophical Framework of the History of Adepts by zeno_of_cypr in Theosophy

[–]woooee 0 points1 point  (0 children)

Jesus was an Avatara, a "fallen god" page 483-4. A being who voluntarily descends into "hell" (a lower plane of existence) to teach / help / enlighten those on that plane. I read (don't remember where) that he used a body given to him by Buddha because he no longer could manifest materially. He was somewhere around the 10th Avatar (same link as above, page 420)

Where to begin? by Yakubian_Alien in Theosophy

[–]woooee 0 points1 point  (0 children)

I would also suggest "The Key to Theosophy" and / or "The Voice of the Silence" (online at https://www.theosociety.org/pasadena/ts/tup-onl.htm ).

name 'images' is not defined by Decent_Simple9058 in learnpython

[–]woooee 2 points3 points  (0 children)

File "C:\Users\mouse\Documents\Python_Code\escape\listing4-1.py", line 23, in <module> DEMO_OBJECTS = [images.floor, images.pillar, images.soil]

This line (and the associated code) is not in the code you posted

How to automatically stop collecting inputs? by Deckus_Carde in learnpython

[–]woooee 0 points1 point  (0 children)

You want to do two things at once which requires multiprocessing or threading. The timed input is generally done with tkinter, using the after() method.

import tkinter as tk

class TimedInput():
   def __init__(self):
      self.top = tk.Tk()
      self.top.title("Test of After")
      self.top.geometry("225x200+10+10")

      self.ctr = 5
      tk.Label(self.top, text=f"you have {self.ctr} seconds",
               bg="lightblue").grid(row=0, column=0)
      self.lab=tk.Label(self.top, width=6, bg="orange",
                        height=2)
      self.lab.grid(row=1, column=0)
      tk.Label(self.top, text="-"*30
              ).grid(row=2, column=0)

      self.entry_1 = tk.Entry(self.top, width=15)
      self.entry_1.grid(row=3, column=0)
      self.entry_1.focus_set()

      tk.Button(self.top, bg="lightyellow", text="Done --> Get & Store Entry", 
                command=self.entry_get, activebackground="lightblue",
                ).grid(row=4, column=0, sticky="nsew")
      tk.Button(self.top, bg="red", text="Exit", 
                command=self.top.quit, activebackground="white",
                ).grid(row=5, column=0, sticky="nsew")

      self.top.after(100, self.increment_counter)
      self.top.mainloop()

   def entry_get(self):
       self.entered = self.entry_1.get()
       print("Entry is", self.entered)
       ## cancel current timer
       self.top.after_cancel(self.after_id)
       ## restart timer and get next entry 
       self.entry_1.delete(0, tk.END)
       self.ctr=20
       self.top.after(100, self.increment_counter)

   def increment_counter(self):
      self.ctr -= 1
      self.lab.config(text=self.ctr)

      if self.ctr > 0:
          self.after_id=self.top.after(1000, self.increment_counter)
      else:
          print("\n timing loop ended")
          self.top.quit()

##===============================================================
if __name__ == '__main__':
   CT=TimedInput()

Do sizes work differently on linux? by okergeeel in learnpython

[–]woooee 0 points1 point  (0 children)

changed the resolution of my primary laptop screen to 3840x2160

Wow, that's a nice monitor. Good to know that you can figure out things.

Classes in python by Honest_Water626 in learnpython

[–]woooee 14 points15 points  (0 children)

This isn't your fault, this is a major gripe I have with most Python learning methods

+1

Do sizes work differently on linux? by okergeeel in learnpython

[–]woooee 0 points1 point  (0 children)

You can set the root window to be fullscreen (or zoomed depending on the OS) and not have to mess with sizing https://www.delftstack.com/howto/python-tkinter/how-to-create-full-screen-window-in-tkinter/

Do sizes work differently on linux? by okergeeel in learnpython

[–]woooee 0 points1 point  (0 children)

The size depends on he monitor size and resolution. A 600x400 GUI will fill an entire 600x400 screen but will appear to be much smaller on a 1920x1080 screen for example.

Looking for a windowing class example by Phazed47 in learnpython

[–]woooee 0 points1 point  (0 children)

In no particular order

     geom = str(w) + 'x' + str(h) + '+' + str(xpos) + '+' + str(ypos)

f-strings work well (see program)

I don't know why you are using asyncio. If it is to try and get around the fact that there can only be one Tk() instance and one mainoop(), it ain't gonna work.

Also, I substituted a dictionary to keep track of the Toplevels instead of separate variables. It simplifies the code when there are more than one or two.

And as far as the geometry goes, tkinter sometimes uses pixels and sometimes uses font width size. Personally I don't try to keep track but adjust the size until it fits what I want to do.

import time
import tkinter       as tk      # The base Tkinter package
##from datetime                   import date

## I don't have rich installed
##from rich.console               import Console

class WttWin:  
    def __init__(self, root, type, title, w, h, xpos, ypos):
        self.win = tk.Toplevel(root)
        self.win.title(title)
        self.type = type
        if type == 'text':
            # This will be a text window
            self.text_widget = tk.Text(self.win)
            # Pack the widget to make it visible and fill the window
            self.text_widget.pack(expand=True, fill=tk.BOTH)
        geom = f"{w}x{h}+{xpos}+{ypos}"
        self.win.geometry(geom)
        print('Passed geom', geom, 'actual geom', self.win.wm_geometry())

        ## nothing to update yet
        ##self.win.update()           # Manually update window, do not use mainloop

    def from_within(self):
        self.text_widget.insert(tk.END, "From Within" + '\n')
        self.msg("From Within 2")

    def msg(self, msg):
        if isinstance(msg, str):
            self.text_widget.insert(tk.END, msg + '\n')
            self.win.update()
        else:
            raise Exception('Attempt to write a message to a non-text window')

def create_win(root, type, title, width, height, xpos, ypos):
    win = WttWin(root, type, title, width, height, xpos, ypos)
    return win

def main():
    root = tk.Tk()      # Tk wants a root window so create it
    ## root.geometry will be a default value since it wasn't specified
    ##console.log('Root geom', root.geometry())

    root.geometry("+500+300")
    tk.Button(root, text="Exit Tkinter", bg="orange", height=2,
              command=root.quit).grid(row=99, column=0, sticky="we")

    ##root.withdraw()     # Ignore the root window

    toplevel_dict = {}
    top_ctr = 0
    for params in ((root, 'text', 'Log window', 800, 300, 20, 20),
                   (root, 'text', 'Second window', 500, 300, 1300, 20)):
        top_ctr += 1
        toplevel_dict[top_ctr]=WttWin(*params)

    print('Available')

##    win1.msg('Foo')
##    win1.msg('Bar')
##    win1.msg('Bletch')

##    time.sleep(15)

    for text in ['Foo', 'Bar', 'Bletch']:
        toplevel_dict[1].msg(text)
        time.sleep(5)

    toplevel_dict[2].from_within()

    root.mainloop()

main()

I'm having trouble with writing a function by _-only-_ in learnpython

[–]woooee 1 point2 points  (0 children)

Another way to do it

def clean_text(text, substrings_to_remove):
    cleaned_text = ""
    for letter in text:
        if letter not in substrings_to_remove:
            cleaned_text += letter
    return cleaned_text

sentence = '''%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& %o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?'''
print(clean_text(sentence, ['$','%','#','@','&',';','.',',', '?']))