Question

So for one of my classes I am updating the game Minesweeper. So for the game...

So for one of my classes I am updating the game Minesweeper. So for the game I was wanting to change the size of the grid based on user preference. I am new to working with tkMesseageBoxs. I am trying to update the variable SIZE_X and SIZE_Y with the tkMeassage box. Size_x and Size_y control the size of the grid. For the first one I tried assigning it to the variable a and b. For the other variables I was having trouble returning them. When I run the minesweeper game it only shows a blank screen. I am having trouble returning the variables back into the game. If you can help, it would be greatly appreciated.


ak: bool = tkMessageBox.askyesno("Difficulty", "Would you like to play the easy version?")
if ak:
a = 10
b = 10

else:
ka = tkMessageBox.askyesno("Difficulty", "Would you like to play a harder version?")
if ka:
SIZE_X = 20
SIZE_Y = 20
else:
akk = tkMessageBox.showinfo("Difficulty", "Looks like you will play the harder version after all.")
SIZE_X = 35
SIZE_Y = 35

SIZE_X = a
SIZE_Y = b

STATE_DEFAULT = 0
STATE_CLICKED = 1
STATE_FLAGGED = 2
WINS = 0


the programming language is python.

Homework Answers

Answer #1

I am assuming that you are using python 3. This is allbecause there are changes in the python 3.

Here is my code that will allow you to decide window size as par your requirement. also maintain those indentation :

from tkinter import *
import tkinter.messagebox

gui = Tk(className='Python Examples - Window Size')
# set window size
#gui.geometry("300x300")



ak: bool = tkinter.messagebox.askyesno("Difficulty", "Would you like to play the easy version?")
if ak:
    a = 200
    b = 200
    gui.geometry('%dx%d' % (a, b))
else:
    ka = tkinter.messagebox.askyesno("Difficulty", "Would you like to play a harder version?")
    
    if ka:
        a = 400
        b = 400
        gui.geometry('%dx%d' % (a, b))
    else:
        akk = tkinter.messagebox.showinfo("Difficulty", "Looks like you will play the harder version after all.")
        a = 600
        b = 600
        gui.geometry('%dx%d' % (a, b))


gui.mainloop() 

Another way, where the window will close and open the game window as you want:

import tkinter as tk

def easy():
    mw.destroy()
    gui = tk.Tk(className='Python Examples - Window Size')
    a = 200
    b = 200
    gui.geometry('%dx%d' % (a, b))
    gui.mainloop()
    
def harder():
    mw.destroy()
    gui = tk.Tk(className='Python Examples - Window Size')
    a = 400
    b = 400
    gui.geometry('%dx%d' % (a, b))
    gui.mainloop()
    
 
def tough():
    mw.destroy()
    gui = tk.Tk(className='Python Examples - Window Size')
    a = 600
    b = 600
    gui.geometry('%dx%d' % (a, b))
    gui.mainloop()

mw = tk.Tk()

#If you have a large number of widgets, like it looks like you will for your
#game you can specify the attributes for all widgets simply like this.
mw.option_add("*Button.Background", "white")
mw.option_add("*Button.Foreground", "black")

mw.title('The game')
#You can set the geometry attribute to change the root windows size
mw.geometry("200x200") #You want the size of the app to be 500x500
mw.resizable(0, 0) #Don't allow resizing in the x or y direction

back = tk.Frame(master=mw,bg='white')
back.pack_propagate(0) #Don't allow the widgets inside to determine the frame's width / height
back.pack(fill=tk.BOTH, expand=1) #Expand the frame to fill the root window

#Changed variables so you don't have these set to None from .pack()
go1 = tk.Button(master=back, text='Easy', command=easy)
go1.pack(side=tk.LEFT)
go2 = tk.Button(master=back, text='Harder', command=harder)
go2.pack(side=tk.LEFT)
go3 = tk.Button(master=back, text='Tough', command=tough)
go3.pack(side=tk.LEFT)
close = tk.Button(master=back, text='Quit', command=mw.destroy)
close.pack(side=tk.LEFT)


mw.mainloop()
Know the answer?
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
Similar Questions
HI i am having trouble with my post lab report. It involved Delta H, specific heat...
HI i am having trouble with my post lab report. It involved Delta H, specific heat and other things i am having trouble calculating. I have uploaded the images onto a google document https://docs.google.com/document/d/1VQi5tjHzD-mmVQqBvdczQdkBRWSPpV7N5vY2xlL_Gmw/edit?usp=sharing I AM ONLY ASKING YOU TO complete the questions on PAGE 4 of the google doc. I WOULD HIGHLY APPRECIATE IF IF YOU WOULD SHOW STEP BY STEP, AND EXACTLY WHAT NUMBERS REPRESENT WHICH VARIABLES. Please help me out, I am really struggling in my chemistry...
So I am having a really hard time on my investments homework. I would be grateful...
So I am having a really hard time on my investments homework. I would be grateful to just see examples like these so that I understand how to do them. My textbook is no help. 2.         XYZ stock traded last at $30.00 per share. Provide an example of a buy limit order that you might place, and indicate how it would work.         b.    Suppose you bought XYZ's stock at $30.00 per share. Explain the stop order that...
Hello! I am coding in c# and I am having trouble using boolean variables and if...
Hello! I am coding in c# and I am having trouble using boolean variables and if statements. The project I am working on is based on the users input, and the code should branch into two different options. However, I am struggling to understand how to take the users input to decide which path to take. Another problem I am having is with my if statements. After the user has inputed information and the code decides to take them down...
I am having trouble with a Cybertext problem in the Cost Volume Relationships - Profit Planning...
I am having trouble with a Cybertext problem in the Cost Volume Relationships - Profit Planning section. It reads: For 20x2 the selling price per lamp will be $45. The company would like to have a operating income equal to 31% of sales. If that is to be achieved, what would be the sales in units in 20x2? There's no other data given. From previous problems: Fixed Costs: $380,000, Contribution Margin per Unit is 21.7018250 Variable Cost per Unit: $23.2981750
*******I am studying for an upcoming test and I am having trouble with QUESTION B) where...
*******I am studying for an upcoming test and I am having trouble with QUESTION B) where I need to find the sample variances for the two cooperatives (BT) and (PA) I would like to see how you end up with 135.14 and 749.70? I am confused about the capital E symbol and why it is used when finding cooperative? 8.80 Lobster trap placement. Given trap spacings among two lobster fishing crews: BT cooperative has spacings = {93, 99, 105, 94,...
I am having problems with an assignment for my class, I am struggling with part a...
I am having problems with an assignment for my class, I am struggling with part a of the following question. I included parts b-d as these additional questions may influence the answer to part a To generate leads for new business, Gustin Investment Services offers free financial planning seminars at major hotels in Southwest Florida. Gustin conducts seminars for groups of 25 individuals. Each seminar costs Gustin $3500, and the average first-year commission for each new account opened is $5000....
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...
Binary Search Tree with multiple structs? Hi, I am having an issue with trying to create...
Binary Search Tree with multiple structs? Hi, I am having an issue with trying to create a binary search tree while having multiple structs. The struct code provided is provided for us. #define CAT_NAME_LEN 25 #define APP_NAME_LEN 50 #define VERSION_LEN 10 #define UNIT_SIZE 3 struct app_info{ char category[CAT_NAME_LEN]; // name of category char app_name[APP_NAME_LEN]; // name of application char version[VERSION_LEN]; // version number float size; // size of application char units[UNIT_SIZE]; // GB or MB float price; // price in...
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
I am having an issue with my school's math program but first want to ensure it...
I am having an issue with my school's math program but first want to ensure it is the program and not my process. Question- You want to obtain a sample to estimate a population proportion. At this point in time, you have no reasonable preliminary estimation for the population proportion. You would like to be 99% confident that you estimate is within 3.5% of the true population proportion. How large of a sample size is required? (1-0.99)/2 = 0.005 invNorm...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT