0

I'm making a Tic Tac Toe game and utilizing tkinter for framing. I'm able to create the buttons for player aka "X" and changes when the button is pressed but for the computer or "O" I can't seem to find how to rng the button press to change the button text.

I have the algorithm working for the program I'm just trying use tkinters framing to make it more visually appealing.

Alen
  • 1
  • 1
    Are you aware python has a module named [random](https://docs.python.org/3/library/random.html) that can be used to generate random numbers? – Bryan Oakley Oct 17 '22 at 20:16
  • Please don't use abbreviations. What do you mean by "rng"? – President James K. Polk Oct 17 '22 at 20:24
  • Yes, I have the whole program working, including random for computer. I just don't know how to generate random event in tkinter to simulate computer button press... – Alen Oct 17 '22 at 20:24
  • 1
    @PresidentJamesK.Polk RNG = Random Number Generator, this is a well-known abbreviation. – Barmar Oct 17 '22 at 20:24
  • @Barmar: Of course I know that definition, but it makes no sense in the context of OPs question. – President James K. Polk Oct 17 '22 at 20:25
  • Why do you think adding tkinter for the UI makes any difference to how you generate the moves randomly? – Barmar Oct 17 '22 at 20:25
  • @PresidentJamesK.Polk I don't understand where is the confusion? – Alen Oct 17 '22 at 20:26
  • 1
    You shouldn't generate moves randomly. You should use an algorithm to select the best move to prevent the opponent from winning. – Barmar Oct 17 '22 at 20:27
  • @Barmar I can't figure out how to simulate that. – Alen Oct 17 '22 at 20:27
  • @Barmar Yes that is the next step but for now I need a way to simulate computer pick with tkinter. – Alen Oct 17 '22 at 20:28
  • If you have a list of elements where you display the moves, you select a random element of the list, and then set its text to `O`. – Barmar Oct 17 '22 at 20:28
  • @Barmar yes that's what I'm doing and that portion is working but how do I get text to populate the button on tkinter after players turn? – Alen Oct 17 '22 at 20:29
  • What is the issue? If you know how to change the text of the player's button, you use the same method to change the text of the computer's button. https://stackoverflow.com/questions/32615440/python-3-tkinter-how-to-update-button-text – Barmar Oct 17 '22 at 20:31
  • That thread helps, thanks – Alen Oct 17 '22 at 20:35
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – user16217248 Oct 18 '22 at 01:32

0 Answers0